Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix 'd' & 'y' in vi-mode to work for visual-block mode.
  • Loading branch information
fukamachi committed Aug 17, 2023
commit 5d81ca157ff89f53fbeb9230f21e2d7979599fb7
4 changes: 3 additions & 1 deletion extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@

(define-vi-operator vi-delete (start end type) ()
(let ((pos (point-charpos (current-point))))
(with-killring-context (:options (when (eq type :line) :vi-line))
(with-killring-context (:options (when (eq type :line) :vi-line)
:appending (when (eq type :block)
(continue-flag :kill)))
(kill-region start end))
(when (and (eq type :line)
(eq 'vi-delete (command-name (this-command))))
Expand Down
56 changes: 32 additions & 24 deletions extensions/vi-mode/commands/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(:import-from :lem-vi-mode/visual
:visual-p
:visual-line-p
:visual-block-p
:apply-visual-range
:vi-visual-end)
(:import-from :lem/common/command
Expand Down Expand Up @@ -89,7 +90,7 @@
(t (values arg-list '("P") nil))))

(defmacro define-vi-motion (name arg-list (&key type jump) &body body)
(check-type type (or null (member :inclusive :exclusive :line)))
(check-type type (or null (member :inclusive :exclusive :line :block)))
(check-type jump boolean)
(multiple-value-bind (arg-list arg-descriptor default-n-arg)
(parse-vi-motion-arg-list arg-list)
Expand Down Expand Up @@ -161,29 +162,36 @@
(command-motion-type command))))))))))

(defun call-vi-operator (n fn &key motion keep-visual restore-point)
(with-point ((*vi-origin-point* (current-point)))
(unwind-protect
(if *vi-operator-arguments*
(apply fn *vi-operator-arguments*)
(multiple-value-bind (start end type)
(vi-operator-region n motion)
(when (point< end start)
(rotatef start end))
(ecase type
(:line (unless (visual-p)
(line-start start)
(line-end end)))
(:inclusive
(unless (point= start end)
(character-offset end 1)))
(:exclusive))
(let ((*vi-operator-arguments* (list start end type)))
(funcall fn start end type))))
(when restore-point
(move-point (current-point) *vi-origin-point*))
(unless keep-visual
(when (visual-p)
(vi-visual-end))))))
(flet ((call-with-region (fn start end type)
(when (point< end start)
(rotatef start end))
(ecase type
(:line (unless (visual-p)
(line-start start)
(line-end end)))
(:block)
(:inclusive
(unless (point= start end)
(character-offset end 1)))
(:exclusive))
(let ((*vi-operator-arguments* (list start end type)))
(funcall fn start end type))))
(with-point ((*vi-origin-point* (current-point)))
(unwind-protect
(if *vi-operator-arguments*
(apply fn *vi-operator-arguments*)
(if (visual-block-p)
(apply-visual-range
(lambda (start end)
(call-with-region fn start end :block)))
(multiple-value-bind (start end type)
(vi-operator-region n motion)
(call-with-region fn start end type))))
(when restore-point
(move-point (current-point) *vi-origin-point*))
(unless keep-visual
(when (visual-p)
(vi-visual-end)))))))

(defmacro define-vi-operator (name arg-list (&key motion keep-visual restore-point) &body body)
(with-gensyms (n extra-args)
Expand Down