Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes point leaks in vi-mode. #1236

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 26 additions & 26 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,32 @@
(bolp p)))

(define-command vi-forward-word-begin (&optional (n 1)) ("p")
(let ((start-line (line-number-at-point (current-point)))
(origin (copy-point (current-point))))
(dotimes (i n)
(forward-word-begin #'word-char-type))
;; In operator-pending mode, this motion behaves differently.
(when (operator-pending-mode-p)
(with-point ((p (current-point)))
;; Go back to the end of the previous line when the END point is in the next line.
;; For example, when the cursor is at [b],
;; foo [b]ar
;; baz
;; 'dw' deletes only the 'bar', instead of deleting to the beginning of the next word.
(skip-whitespace-backward p t)
(when (and (point< origin p)
(bolp p))
(line-offset p -1)
(line-end p)
(loop while (and (< start-line
(line-number-at-point p))
(on-only-space-line-p p))
do (line-offset p -1)
(line-end p))
;; Skip this line if the previous line is empty
(when (bolp p)
(character-offset p 1))
(move-point (current-point) p))))))
(let ((start-line (line-number-at-point (current-point))))
(with-point ((origin (current-point)))
(dotimes (i n)
(forward-word-begin #'word-char-type))
;; In operator-pending mode, this motion behaves differently.
(when (operator-pending-mode-p)
(with-point ((p (current-point)))
;; Go back to the end of the previous line when the END point is in the next line.
;; For example, when the cursor is at [b],
;; foo [b]ar
;; baz
;; 'dw' deletes only the 'bar', instead of deleting to the beginning of the next word.
(skip-whitespace-backward p t)
(when (and (point< origin p)
(bolp p))
(line-offset p -1)
(line-end p)
(loop while (and (< start-line
(line-number-at-point p))
(on-only-space-line-p p))
do (line-offset p -1)
(line-end p))
;; Skip this line if the previous line is empty
(when (bolp p)
(character-offset p 1))
(move-point (current-point) p)))))))

(define-command vi-backward-word-begin (&optional (n 1)) ("p")
(dotimes (i n)
Expand Down
4 changes: 2 additions & 2 deletions extensions/vi-mode/commands/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
(or (range-type retval) :exclusive)))
(otherwise
(values start
(copy-point (current-point))
(copy-point (current-point) :temporary)
(command-motion-type command)))))))
(command-motion-type (command)
(if (typep command 'vi-motion)
Expand All @@ -162,7 +162,7 @@
(save-excursion
(ignore-some-conditions (end-of-buffer)
(next-logical-line (1- (or uarg 1))))
(values start (copy-point (current-point)) :line))
(values start (copy-point (current-point) :temporary) :line))
;; raise error for invalid commands
(error 'editor-abort :message nil)))
(otherwise
Expand Down
19 changes: 8 additions & 11 deletions extensions/vi-mode/visual.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,18 @@
(typep (current-main-state) 'visual-block))

(defun visual-range ()
(cond
((visual-char-p)
(with-point ((start *start-point*)
(end (current-point)))
(with-point ((start *start-point*)
(end (current-point)))
(cond
((visual-char-p)
(cond ((point<= start end)
(character-offset end 1))
((point< end start)
(character-offset start 1)))
(list start end)))
((visual-block-p)
(list (copy-point *start-point*)
(copy-point (current-point))))
(t
(with-point ((start *start-point*)
(end (current-point)))
(list start end))
((visual-block-p)
(list start end))
(t
(when (point< end start)
(rotatef start end))
(line-start start)
Expand Down
2 changes: 1 addition & 1 deletion extensions/vi-mode/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(window-view-point window))

(defun window-end-point (&optional (window (current-window)))
(let ((point (copy-point (window-start-point window))))
(let ((point (copy-point (window-start-point window) :temporary)))
(move-to-next-virtual-line point (1- (window-height* window)) window)
point))

Expand Down