From 3929f94e69ccd7b062269e390b0afda953c7133b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20G=C3=B6ttschkes?= Date: Fri, 5 Jan 2024 22:28:27 +0100 Subject: [PATCH 1/3] Fixes a point leak in vi-mode window-end-point. --- extensions/vi-mode/window.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vi-mode/window.lisp b/extensions/vi-mode/window.lisp index c5995e5d2..322d31522 100644 --- a/extensions/vi-mode/window.lisp +++ b/extensions/vi-mode/window.lisp @@ -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)) From 015b78b39baad03bec81398f310efa07bad888bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20G=C3=B6ttschkes?= Date: Fri, 5 Jan 2024 22:36:52 +0100 Subject: [PATCH 2/3] Fixes a point leak in vi-mode vi-forward-word-begin. --- extensions/vi-mode/commands.lisp | 52 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/extensions/vi-mode/commands.lisp b/extensions/vi-mode/commands.lisp index f8c5409b1..8bd02f2ee 100644 --- a/extensions/vi-mode/commands.lisp +++ b/extensions/vi-mode/commands.lisp @@ -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) From fe84475d493ba72a45a54674071c3a2afda5d581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20G=C3=B6ttschkes?= Date: Fri, 5 Jan 2024 23:16:15 +0100 Subject: [PATCH 3/3] Fixes a point leaks in vi-mode range creation. --- extensions/vi-mode/commands/utils.lisp | 4 ++-- extensions/vi-mode/visual.lisp | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/extensions/vi-mode/commands/utils.lisp b/extensions/vi-mode/commands/utils.lisp index eec7cf9ef..80d9f7843 100644 --- a/extensions/vi-mode/commands/utils.lisp +++ b/extensions/vi-mode/commands/utils.lisp @@ -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) @@ -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 diff --git a/extensions/vi-mode/visual.lisp b/extensions/vi-mode/visual.lisp index 24e64aac5..a3b0395d6 100644 --- a/extensions/vi-mode/visual.lisp +++ b/extensions/vi-mode/visual.lisp @@ -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)