Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lem-project/lem into sync-mark-regi…
Browse files Browse the repository at this point in the history
…on-for-vi-mode
  • Loading branch information
sakurawald committed Dec 10, 2024
2 parents dcda508 + 3f325ba commit e974634
Show file tree
Hide file tree
Showing 53 changed files with 752 additions and 211 deletions.
1 change: 1 addition & 0 deletions extensions/java-mode/java-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ see : https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html
:mode-hook *java-mode-hook*)
(setf (variable-value 'enable-syntax-highlight) t
(variable-value 'indent-tabs-mode) nil
(variable-value 'calc-indent-function) 'lem-c-mode::calc-indent
(variable-value 'tab-width) 2
(variable-value 'line-comment) "//"))

Expand Down
3 changes: 2 additions & 1 deletion extensions/java-mode/lem-java-mode.asd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

(defsystem "lem-java-mode"
:depends-on ("lem")
:depends-on ("lem"
"lem-c-mode")
:serial t
:components ((:file "java-mode")))

5 changes: 2 additions & 3 deletions extensions/legit/legit-commit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ Future:
|#

;; major-mode for the commit buffer.
(define-major-mode legit-commit-mode lem-markdown-mode:markdown-mode
(define-major-mode legit-commit-mode ()
(:name "legit-commit-mode"
:syntax-table lem-markdown-mode::*markdown-syntax-table*
:keymap *legit-commit-mode-keymap*)
;; no syntax highlihgt in fact.
;; no syntax highlight in fact.
(setf (variable-value 'enable-syntax-highlight) t))

(define-file-associations legit-commit-mode
Expand Down
2 changes: 1 addition & 1 deletion extensions/legit/legit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Currently Git-only. Concretely, this calls Git with the -w option.")
(message "Could not parse hunk information"))))))

(defparameter *commit-buffer-message*
"~%# Please enter the commit message for your changes.~%~
"~%~%# Please enter the commit message for your changes.~%~
# Lines starting with '#' will be discarded, and an empty message does nothing.~%~
# Validate with C-c C-c, quit with M-q or C-c C-k")

Expand Down
6 changes: 5 additions & 1 deletion extensions/lisp-mode/connection.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:connection-command
:connection-process
:connection-process-directory
:connection-system-file-patterns
:connection-plist
:self-connection-p)
(:export :new-connection
Expand Down Expand Up @@ -118,6 +119,7 @@
:type string
:documentation "The server's Swank version.")
(features :accessor connection-features)
(system-file-patterns :accessor connection-system-file-patterns)
(info :accessor connection-info)
(command :initform nil :accessor connection-command)
(process :initform nil :accessor connection-process)
Expand Down Expand Up @@ -200,7 +202,9 @@
(connection-package connection)
(getf (getf data :package) :name)
(connection-prompt-string connection)
(getf (getf data :package) :prompt)))
(getf (getf data :package) :prompt)
(connection-system-file-patterns connection)
(getf data :system-file-patterns)))
(return)))

(log:debug "Creating the REPL" connection)
Expand Down
3 changes: 3 additions & 0 deletions extensions/lisp-mode/ext/detective.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
(defmethod capture-reference ((position lem:point) (class (eql :package-reference)))
(%default-capture 'lem/detective:package-reference position))

(defmethod capture-reference ((position lem:point) (class (eql :macro-reference)))
(%default-capture 'lem/detective:macro-reference position))

(defmethod capture-reference ((position lem:point) (class (eql :misc-reference)))
(ppcre:register-groups-bind (type name)
("^\\s*\\(\\s*(\\w+)\\s+(.*)\\s*" (line-string position))
Expand Down
2 changes: 1 addition & 1 deletion extensions/lisp-mode/file-conversion.lisp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(in-package :lem-lisp-mode/internal)

(defvar *file-conversion-map* '()
"This variable is a alist for converting remote file names to local file names.
"This variable is an alist for converting remote file names to local file names.
Uses include mapping files in docker to files in the local environment.
For example, set the following.
Expand Down
3 changes: 3 additions & 0 deletions extensions/lisp-mode/lem-lisp-mode.asd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
(:file "ext/test-runner")
(:file "ext/utopian")
(:file "ext/highlight")

(:file "read-only-sources")

(:file "package")))

(defsystem "lem-lisp-mode/v2"
Expand Down
4 changes: 4 additions & 0 deletions extensions/lisp-mode/lisp-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
(lem/detective:make-capture-regex
:regex "^(?:\\(defvar |\\(defparameter )"
:function #'lem-lisp-mode/detective:capture-reference)
:macro-regex
(lem/detective:make-capture-regex
:regex "^\\(defmacro "
:function #'lem-lisp-mode/detective:capture-reference)
:misc-regex
(lem/detective:make-capture-regex
:regex "^\\(deftest "
Expand Down
14 changes: 14 additions & 0 deletions extensions/lisp-mode/read-only-sources.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(uiop:define-package :lem-lisp-mode/read-only-sources
(:use :cl)
(:import-from :lem/read-only-sources
:define-read-only-source))
(in-package :lem-lisp-mode/read-only-sources)

(define-read-only-source sbcl-source (directory)
(alexandria:when-let (connection (lem-lisp-mode/internal:current-connection))
(dolist (pattern (lem-lisp-mode/connection:connection-system-file-patterns connection))
(when (pathname-match-p directory pattern)
(return t)))))

(define-read-only-source quicklisp-dists (directory)
(search "/dists/quicklisp/software/" directory))
9 changes: 7 additions & 2 deletions extensions/lisp-mode/repl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
(list (make-tm-region
"^WARNING:"
"$"
:name 'warning-attribute))))
:name 'warning-attribute)
(make-tm-match "^; caught WARNING:"
:name 'warning-attribute)
(make-tm-match "^; caught ERROR:"
:name 'warning-attribute))))

(define-major-mode lisp-repl-mode lisp-mode
(:name "REPL"
Expand Down Expand Up @@ -522,7 +526,8 @@
(defvar *lisp-repl-shortcuts* '())

(defmacro with-repl-prompt (() &body body)
`(let ((lem/prompt-window:*prompt-completion-window-shape* nil))
`(let ((lem/prompt-window:*prompt-completion-window-shape* nil)
(lem/prompt-window::*fill-width* nil))
,@body))

(defun repl-prompt-for-string (prompt &rest args)
Expand Down
2 changes: 2 additions & 0 deletions extensions/vi-mode/binds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
(define-key *motion-keymap* "C-w C-j" 'undefined-key)
(define-key *motion-keymap* "C-o" 'vi-jump-back)
(define-key *motion-keymap* "C-i" 'vi-jump-next)
(define-key *motion-keymap* "' '" 'vi-jump-previous)
(define-key *motion-keymap* ":" 'vi-ex)

(define-key *motion-keymap* "v" 'vi-visual-char)
Expand Down Expand Up @@ -128,6 +129,7 @@
(define-key *normal-keymap* "g U" 'vi-upcase)
(define-key *normal-keymap* "g u" 'vi-downcase)
(define-key *normal-keymap* "g ~" 'vi-swapcase)
(define-key *normal-keymap* "~" 'vi-swapcase-and-forward-char)
(define-key *normal-keymap* "u" 'vi-undo)
(define-key *normal-keymap* "C-r" 'vi-redo)
(define-key *motion-keymap* 'delete-previous-char 'vi-backward-char)
Expand Down
105 changes: 65 additions & 40 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
:vi-upcase
:vi-downcase
:vi-swapcase
:vi-swapcase-and-forward-char
:vi-undo
:vi-redo
:vi-record-macro
Expand Down Expand Up @@ -122,8 +123,10 @@
:vi-append-line
:vi-open-below
:vi-open-above
:vi-jumps
:vi-jump-back
:vi-jump-next
:vi-jump-previous
:vi-a-word
:vi-a-word
:vi-a-broad-word
Expand Down Expand Up @@ -529,46 +532,52 @@ Move the cursor to the first non-blank character of the line."
(t :char)))
(and (enable-clipboard-p) (get-clipboard-data)))))

(define-command vi-paste-after () ()
(multiple-value-bind (string type)
(vi-yank-from-clipboard-or-killring)
(cond
((visual-p)
(let ((visual-line (visual-line-p)))
(define-command vi-paste-after (&optional (n 1)) (:universal)
(dotimes (i n)
(multiple-value-bind (string type)
(vi-yank-from-clipboard-or-killring)
(cond
((visual-p)
(let ((visual-line (visual-line-p)))
(lem-core::with-enable-clipboard nil
(multiple-value-bind (beg end type)
(visual-region)
(vi-delete beg end type))
(rotate-killring (current-killring)))
(when (and (not visual-line)
(eq type :line))
(insert-character (current-point) #\Newline))))
(t
(if (eq type :line)
(progn
(or (line-offset (current-point) 1 0)
(progn
(line-end (current-point))
(insert-character (current-point) #\Newline))))
(character-offset (current-point) 1))))
(paste-yank string type :after))))

(define-command vi-paste-before (&optional (n 1)) (:universal)
(dotimes (i n)
(multiple-value-bind (string type)
(vi-yank-from-clipboard-or-killring)
(cond
((visual-p)
(lem-core::with-enable-clipboard nil
(multiple-value-bind (beg end type)
(visual-region)
(vi-delete beg end type))
(rotate-killring (current-killring)))
(when (and (not visual-line)
(eq type :line))
(insert-character (current-point) #\Newline))))
(t
(if (eq type :line)
(progn
(or (line-offset (current-point) 1 0)
(progn
(line-end (current-point))
(insert-character (current-point) #\Newline))))
(character-offset (current-point) 1))))
(paste-yank string type :after)))

(define-command vi-paste-before () ()
(multiple-value-bind (string type)
(vi-yank-from-clipboard-or-killring)
(cond
((visual-p)
(lem-core::with-enable-clipboard nil
(multiple-value-bind (beg end type)
(visual-region)
(vi-delete beg end type))
(rotate-killring (current-killring)))
(when (eq type :line)
(insert-character (current-point) #\Newline)))
(t
(when (eq type :line)
(line-start (current-point)))))
(paste-yank string type :before)))
(when (eq type :line)
(insert-character (current-point) #\Newline)))
(t
(when (eq type :line)
(if (last-line-p (current-point))
(progn
(line-start (current-point))
(open-line 1))
(line-start (current-point))))))
(paste-yank string type :before))))

(defun read-key-to-replace ()
(with-temporary-state 'replace-state
Expand Down Expand Up @@ -639,6 +648,13 @@ Move the cursor to the first non-blank character of the line."
(apply-visual-range #'swapcase-region)
(swapcase-region start end))))

(define-command vi-swapcase-and-forward-char () ()
(with-point ((start (current-point))
(end (current-point)))
(character-offset end 1)
(vi-swapcase start end (current-state)))
(vi-forward-char))

(define-command vi-undo (&optional (n 1)) (:universal)
(undo n))

Expand Down Expand Up @@ -780,18 +796,18 @@ on the same line or at eol if there are none."
(lambda (point string)
(alexandria:when-let (p (lem/isearch::search-forward-regexp
(copy-point lem/isearch::*isearch-start-point* :temporary)
(ppcre:create-scanner string :case-insensitive-mode case-insensitive)))
(ignore-errors (ppcre:create-scanner string :case-insensitive-mode case-insensitive))))
(character-offset p (- (length string)))
(move-point point p)))
(lambda (point regex &optional limit-point)
(lem/isearch::search-forward-regexp
point
(ppcre:create-scanner regex :case-insensitive-mode case-insensitive)
limit-point))
point
(ignore-errors (ppcre:create-scanner regex :case-insensitive-mode case-insensitive))
limit-point))
(lambda (point regex &optional limit-point)
(lem/isearch::search-backward-regexp
point
(ppcre:create-scanner regex :case-insensitive-mode case-insensitive)
(ignore-errors (ppcre:create-scanner regex :case-insensitive-mode case-insensitive))
limit-point))
""))))

Expand Down Expand Up @@ -1003,6 +1019,11 @@ on the same line or at eol if there are none."
(line-start p))))))
(move-to-column (current-point) column t)))

(define-command vi-jumps () ()
(line-end (current-point))
(lem:message-buffer (with-output-to-string (s)
(lem-vi-mode/jumplist::print-jumplist (current-jumplist) s))))

(define-command vi-jump-back (&optional (n 1)) (:universal)
(dotimes (i n)
(jump-back)))
Expand All @@ -1011,6 +1032,10 @@ on the same line or at eol if there are none."
(dotimes (i n)
(jump-next)))

(define-motion vi-jump-previous () ()
(:jump t)
(jump-back))

(define-command vi-repeat (n) (:universal-nil)
(when *last-repeat-keys*
(let ((*enable-repeat-recording* nil)
Expand Down
16 changes: 10 additions & 6 deletions extensions/vi-mode/ex-command.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
(ex-write range filename t)))

(define-ex-command "^bn$" (range argument)
(declare (ignore range argument))
(lem:next-buffer))
(declare (ignore range argument))
(lem:next-buffer))

(define-ex-command "^bp$" (range argument)
(declare (ignore range argument))
(lem:previous-buffer))
(declare (ignore range argument))
(lem:previous-buffer))

(define-ex-command "^wq$" (range filename)
(ex-write-quit range filename nil t))
Expand Down Expand Up @@ -190,8 +190,8 @@
(declare (ignore range))
(lem:pipe-command
(format nil "~A ~A"
(subseq lem-vi-mode/ex-core:*command* 1)
command)))
(subseq lem-vi-mode/ex-core:*command* 1)
command)))

(define-ex-command "^(buffers|ls|files)$" (range argument)
(declare (ignore range argument))
Expand Down Expand Up @@ -259,3 +259,7 @@
(define-ex-command "^pwd?$" (range argument)
(declare (ignore range argument))
(lem:current-directory))

(define-ex-command "^jumps?$" (range argument)
(declare (ignore range argument))
(lem-vi-mode/commands:vi-jumps))
Loading

0 comments on commit e974634

Please sign in to comment.