Skip to content
Merged
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
Refactor code in define-vi-operator regarding visual mode.
  • Loading branch information
fukamachi committed Aug 17, 2023
commit ddf196c4769d804d50eb5368009fb77c07a7de4d
67 changes: 31 additions & 36 deletions extensions/vi-mode/commands/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -126,40 +126,31 @@
(if (typep command 'vi-motion)
(vi-motion-type command)
:exclusive)))
(if (visual-p)
(let (start end)
(apply-visual-range
(lambda (vstart vend)
(setf start vstart
end vend)))
(values start
end
(if (visual-line-p) :line :exclusive)))
(with-point ((start (current-point)))
(if motion
(let ((command (get-command motion)))
(call-motion command n)
(values
start
(copy-point (current-point))
(command-motion-type command)))
(let* ((uarg (or (read-universal-argument) n))
(command-name (read-command))
(command (get-command command-name)))
(typecase command
(vi-operator
(if (eq command-name (command-name (this-command)))
;; Recursive call of the operator like 'dd', 'cc'
(with-point ((end (current-point)))
(line-offset end (1- (or uarg 1)))
(values start end :line))
;; Ignore an invalid operator (like 'dJ')
nil))
(otherwise
(call-motion command uarg)
(values start
(copy-point (current-point))
(command-motion-type command))))))))))
(with-point ((start (current-point)))
(if motion
(let ((command (get-command motion)))
(call-motion command n)
(values
start
(copy-point (current-point))
(command-motion-type command)))
(let* ((uarg (or (read-universal-argument) n))
(command-name (read-command))
(command (get-command command-name)))
(typecase command
(vi-operator
(if (eq command-name (command-name (this-command)))
;; Recursive call of the operator like 'dd', 'cc'
(with-point ((end (current-point)))
(line-offset end (1- (or uarg 1)))
(values start end :line))
;; Ignore an invalid operator (like 'dJ')
nil))
(otherwise
(call-motion command uarg)
(values start
(copy-point (current-point))
(command-motion-type command)))))))))

(defun call-vi-operator (n fn &key motion keep-visual restore-point)
(flet ((call-with-region (fn start end type)
Expand All @@ -180,10 +171,14 @@
(unwind-protect
(if *vi-operator-arguments*
(apply fn *vi-operator-arguments*)
(if (visual-block-p)
(if (visual-p)
(apply-visual-range
(lambda (start end)
(call-with-region fn start end :block)))
(call-with-region fn start end
(cond
((visual-line-p) :line)
((visual-block-p) :block)
(t :exclusive)))))
(multiple-value-bind (start end type)
(vi-operator-region n motion)
(call-with-region fn start end type))))
Expand Down