Skip to content

Commit 5d81ca1

Browse files
committed
Fix 'd' & 'y' in vi-mode to work for visual-block mode.
1 parent 5b11e38 commit 5d81ca1

2 files changed

Lines changed: 35 additions & 25 deletions

File tree

extensions/vi-mode/commands.lisp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@
287287

288288
(define-vi-operator vi-delete (start end type) ()
289289
(let ((pos (point-charpos (current-point))))
290-
(with-killring-context (:options (when (eq type :line) :vi-line))
290+
(with-killring-context (:options (when (eq type :line) :vi-line)
291+
:appending (when (eq type :block)
292+
(continue-flag :kill)))
291293
(kill-region start end))
292294
(when (and (eq type :line)
293295
(eq 'vi-delete (command-name (this-command))))

extensions/vi-mode/commands/utils.lisp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
(:import-from :lem-vi-mode/visual
77
:visual-p
88
:visual-line-p
9+
:visual-block-p
910
:apply-visual-range
1011
:vi-visual-end)
1112
(:import-from :lem/common/command
@@ -89,7 +90,7 @@
8990
(t (values arg-list '("P") nil))))
9091

9192
(defmacro define-vi-motion (name arg-list (&key type jump) &body body)
92-
(check-type type (or null (member :inclusive :exclusive :line)))
93+
(check-type type (or null (member :inclusive :exclusive :line :block)))
9394
(check-type jump boolean)
9495
(multiple-value-bind (arg-list arg-descriptor default-n-arg)
9596
(parse-vi-motion-arg-list arg-list)
@@ -161,29 +162,36 @@
161162
(command-motion-type command))))))))))
162163

163164
(defun call-vi-operator (n fn &key motion keep-visual restore-point)
164-
(with-point ((*vi-origin-point* (current-point)))
165-
(unwind-protect
166-
(if *vi-operator-arguments*
167-
(apply fn *vi-operator-arguments*)
168-
(multiple-value-bind (start end type)
169-
(vi-operator-region n motion)
170-
(when (point< end start)
171-
(rotatef start end))
172-
(ecase type
173-
(:line (unless (visual-p)
174-
(line-start start)
175-
(line-end end)))
176-
(:inclusive
177-
(unless (point= start end)
178-
(character-offset end 1)))
179-
(:exclusive))
180-
(let ((*vi-operator-arguments* (list start end type)))
181-
(funcall fn start end type))))
182-
(when restore-point
183-
(move-point (current-point) *vi-origin-point*))
184-
(unless keep-visual
185-
(when (visual-p)
186-
(vi-visual-end))))))
165+
(flet ((call-with-region (fn start end type)
166+
(when (point< end start)
167+
(rotatef start end))
168+
(ecase type
169+
(:line (unless (visual-p)
170+
(line-start start)
171+
(line-end end)))
172+
(:block)
173+
(:inclusive
174+
(unless (point= start end)
175+
(character-offset end 1)))
176+
(:exclusive))
177+
(let ((*vi-operator-arguments* (list start end type)))
178+
(funcall fn start end type))))
179+
(with-point ((*vi-origin-point* (current-point)))
180+
(unwind-protect
181+
(if *vi-operator-arguments*
182+
(apply fn *vi-operator-arguments*)
183+
(if (visual-block-p)
184+
(apply-visual-range
185+
(lambda (start end)
186+
(call-with-region fn start end :block)))
187+
(multiple-value-bind (start end type)
188+
(vi-operator-region n motion)
189+
(call-with-region fn start end type))))
190+
(when restore-point
191+
(move-point (current-point) *vi-origin-point*))
192+
(unless keep-visual
193+
(when (visual-p)
194+
(vi-visual-end)))))))
187195

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

0 commit comments

Comments
 (0)