[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scroll-on-jump 000dc41039 25/31: Fix error passing out-of-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scroll-on-jump 000dc41039 25/31: Fix error passing out-of-range point to count-screen-lines |
Date: |
Thu, 7 Jul 2022 12:03:14 -0400 (EDT) |
branch: elpa/scroll-on-jump
commit 000dc41039424bf84162c9efad4946d8914b1304
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Fix error passing out-of-range point to count-screen-lines
No longer use point values from before the macro body runs
as the values could be out of range when used with a modified buffer.
All points are now retrieved relative to the modified buffer.
---
scroll-on-jump.el | 49 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)
diff --git a/scroll-on-jump.el b/scroll-on-jump.el
index 11b52c0119..649b7e46e4 100644
--- a/scroll-on-jump.el
+++ b/scroll-on-jump.el
@@ -429,6 +429,32 @@ Moving the point when ALSO-MOVE-POINT is set."
(goto-char point-next))
+;; We cannot store the point before running BODY because
+;; that point may be invalid (outside point-min / point-max for e.g)
+;; after BODY is complete.
+;; Use `save-excursion' & `prog1' so the point's can be retrieved relative
+;; to the modified buffers state.
+;; We could use markers but properly clearing them for garbage-collection
+;; would involve error handling (see note below).
+(defmacro scroll-on-jump--outer-scoped-mark (point-init point-out &rest body)
+ "Set POINT-INIT and store its value in POINT-OUT outside the scope of BODY."
+ `
+ (prog1
+ (save-excursion
+ (goto-char ,point-init)
+ ,@body)
+ (setq ,point-out (point))))
+
+(defmacro scroll-on-jump--inner-scoped-mark (point-init point-out &rest body)
+ "Set POINT-INIT and store its value in POINT-OUT in the scope of BODY."
+ `
+ (save-excursion
+ (prog1
+ (progn
+ (goto-char ,point-init)
+ ,@body)
+ (setq ,point-out (point)))))
+
(defmacro scroll-on-jump--impl (use-window-start &rest body)
"Main macro that wraps BODY in logic that reacts to change in `point'.
Argument USE-WINDOW-START detects window scrolling when non-nil."
@@ -438,17 +464,17 @@ Argument USE-WINDOW-START detects window scrolling when
non-nil."
(buf (current-buffer))
(window (selected-window))
- (point-prev (point))
+ (point-prev nil)
(point-next nil)
(window-start-prev nil)
(window-start-next nil))
- (when ,use-window-start
- (setq window-start-prev (window-start window)))
-
(prog1
- (save-excursion
+ (let
+ ( ;; Postpone point-motion-hooks until later.
+ (inhibit-point-motion-hooks t)
+ (point-orig (point)))
;; Note, we could catch and re-raise errors,
;; this has the advantage that we could get the resulting cursor
location
;; even in the case of an error.
@@ -456,10 +482,13 @@ Argument USE-WINDOW-START detects window scrolling when
non-nil."
;; As it wont show the full back-trace, only the error message.
;; So don't prioritize correct jumping in the case of errors and
assume errors
;; are not something that happen after cursor motion.
- (prog1
- (progn
- ,@body)
- (setq point-next (point))))
+ (scroll-on-jump--outer-scoped-mark point-orig point-prev
+ (scroll-on-jump--outer-scoped-mark (window-start window)
window-start-prev
+ (scroll-on-jump--inner-scoped-mark point-orig point-next
+ ;; Run the main body of this macro.
+ ;; It's important the result if returned (hence the `prog1' use).
+ ,@body))))
+
(cond
( ;; Context changed or recursed, simply jump.
@@ -474,7 +503,7 @@ Argument USE-WINDOW-START detects window scrolling when
non-nil."
(t ;; Perform animated scroll.
(cond
- (window-start-prev
+ (,use-window-start
(setq window-start-next (window-start window))
(unless (eq window-start-prev window-start-next)
(set-window-start window window-start-prev)
- [nongnu] elpa/scroll-on-jump 4b11cda039 07/31: Cleanup: pass the window to count-screen-lines, (continued)
- [nongnu] elpa/scroll-on-jump 4b11cda039 07/31: Cleanup: pass the window to count-screen-lines, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 94986120c4 08/31: readme: add link to demo video, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump fddbdfdfe0 11/31: Fix error where the pixel scroll was left a non-zero value, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 42329b5707 20/31: Fix visual glitch when used with next/previous line, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 5007e9ea8a 18/31: readme: add examples suggested in #2, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 69c86542a1 15/31: Docs: add docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump dd2818d906 17/31: Cleanup: make docstring under 80 chars, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 30dc5f5e50 21/31: Cleanup: remove recursion check, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 28bac2cdc3 22/31: Cleanup: quiet checkdoc warnings for wide docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 0ce93b3ea6 19/31: readme: remove 'evil-goto-first-line' as 'evil-goto-line' already scrolls, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 000dc41039 25/31: Fix error passing out-of-range point to count-screen-lines,
ELPA Syncer <=
- [nongnu] elpa/scroll-on-jump 99386fc01b 30/31: Cleanup: use brief SPDX license, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 556e9a7a81 28/31: Fix error detecting scroll changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 9767013ca8 13/31: Support wrapping functions that themselves scroll, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 8fde237ae6 31/31: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump a614bc7f8f 06/31: Fix the case when the windows buffer is not the current-buffer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 5a6f698b6f 23/31: Cleanup: replace 'if' with 'cond', ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 1e9e09f0cc 29/31: Fix error counting lines jumping to a point outside buffer range, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump a2d6996a36 24/31: Cleanup: use defgroup, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 7b2919f8d8 27/31: Fix smooth (pixel) scrolling not being used in most cases, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 1f2349edf4 04/31: Fix scrolling down when the point is at the beginning of the buffer, ELPA Syncer, 2022/07/07