Skip to content

Commit

Permalink
feature: new command for vi-mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Nov 22, 2024
1 parent 4b55d34 commit 5314cb2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions extensions/vi-mode/binds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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
26 changes: 17 additions & 9 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 @@ -401,10 +402,10 @@ Move the cursor to the first non-blank character of the line."
(max 0
(min (1- (length (line-string (current-point)))) pos))))
(:block
(move-to-line (current-point) (min (line-number-at-point start)
(line-number-at-point end)))
(move-to-column (current-point) (min column-start
column-end))))
(move-to-line (current-point) (min (line-number-at-point start)
(line-number-at-point end)))
(move-to-column (current-point) (min column-start
column-end))))
;; After 'dw' or 'dW', move to the first non-blank char
(when (and (this-motion-command)
(member (command-name (this-motion-command))
Expand Down Expand Up @@ -505,10 +506,10 @@ Move the cursor to the first non-blank character of the line."
(yank-region start end :type type)
(case type
(:block
(move-to-line (current-point) (min (line-number-at-point start)
(line-number-at-point end)))
(move-to-column (current-point) (min (point-column start)
(point-column end))))
(move-to-line (current-point) (min (line-number-at-point start)
(line-number-at-point end)))
(move-to-column (current-point) (min (point-column start)
(point-column end))))
(:line
(move-to-column start (point-charpos (current-point)))
(move-point (current-point) start))
Expand Down Expand Up @@ -639,6 +640,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 () ()
(let* ((start (copy-point (current-point)))
(end (character-offset (current-point) 1)))
;;(editor-error "start = ~a, end = ~a" start end)
(vi-swapcase start end (current-state)))
(vi-forward-char))

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

Expand Down Expand Up @@ -912,7 +920,7 @@ on the same line or at eol if there are none."
(string c)
limit)
unless result
do (return nil)
do (return nil)
finally (return t))
(character-offset p offset)
(move-point (current-point) p)))))
Expand Down

0 comments on commit 5314cb2

Please sign in to comment.