[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scroll-on-drag ca4090af6a 1/2: Cleanup: use generic functi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scroll-on-drag ca4090af6a 1/2: Cleanup: use generic functions storing/restoring the goal column |
Date: |
Sat, 20 Apr 2024 10:02:34 -0400 (EDT) |
branch: elpa/scroll-on-drag
commit ca4090af6af5ccc628200582317d8bd1a17404f1
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Cleanup: use generic functions storing/restoring the goal column
---
scroll-on-drag.el | 61 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 22 deletions(-)
diff --git a/scroll-on-drag.el b/scroll-on-drag.el
index bc36c7e042..4e5eb6df11 100644
--- a/scroll-on-drag.el
+++ b/scroll-on-drag.el
@@ -174,6 +174,10 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as
well."
(run-hooks 'scroll-on-drag-redisplay-hook)
(redisplay)))
+
+;; ---------------------------------------------------------------------------
+;; Internal Evil Workaround
+
(defun scroll-on-drag--evil-visual-line-data ()
"Return data associated with visual line mode or nil when none is found."
;; The checks are written so as not to require evil mode as a dependency.
@@ -198,6 +202,38 @@ VISUAL-LINE-DATA is the result of
`scroll-on-drag--evil-visual-line-data'."
(set-marker ,visual-line-data (point))))
+;; ---------------------------------------------------------------------------
+;; Internal Target Column Functions
+
+(defun scroll-on-drag--goal-column-setup ()
+ "Initialize `goal-column'.
+The result should be passed to `scroll-on-drag--goal-column-restore'."
+ (cons
+ (current-column)
+ (or goal-column
+ (cond
+ ((and temporary-goal-column
+ (memq last-command (list 'next-line 'previous-line 'line-move)))
+ (cond
+ ((consp temporary-goal-column)
+ (car temporary-goal-column))
+ (t
+ temporary-goal-column)))
+ (t
+ nil)))))
+
+(defun scroll-on-drag--goal-column-restore (data)
+ "Restore the goal column from DATA."
+ (pcase-let ((`(,this-column . ,restore-column) data))
+ (unless restore-column
+ (setq temporary-goal-column this-column)
+ (setq restore-column this-column))
+ (when (> restore-column 0)
+ (move-to-column restore-column))
+ ;; Needed so `temporary-goal-column' is respected in the future.
+ (setq this-command 'line-move)))
+
+
;; ---------------------------------------------------------------------------
;; Public Functions
@@ -254,21 +290,8 @@ Returns true when scrolling took place, otherwise nil."
(t
nil)))
- ;; Restore indent (lost when scrolling).
- (this-column (current-column))
- ;; Restore column (may be nil.)
- (restore-column
- (or goal-column
- (cond
- ((and temporary-goal-column
- (memq last-command (list 'next-line 'previous-line
'line-move)))
- (cond
- ((consp temporary-goal-column)
- (car temporary-goal-column))
- (t
- temporary-goal-column)))
- (t
- nil))))
+ ;; Restore column.
+ (goal-column-data (scroll-on-drag--goal-column-setup))
(mouse-y-fn
(cond
@@ -471,13 +494,7 @@ Returns true when scrolling took place, otherwise nil."
;; Restore indent level if possible.
(when has-scrolled
- (unless restore-column
- (setq temporary-goal-column this-column)
- (setq restore-column this-column))
- (when (> restore-column 0)
- (move-to-column restore-column))
- ;; Needed so `temporary-goal-column' is respected in the future.
- (setq this-command 'line-move))
+ (scroll-on-drag--goal-column-restore goal-column-data))
(when has-scrolled-real
(let ((inhibit-redisplay nil))