[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scroll-on-drag 8962f5f8a7 30/35: Add scroll-on-drag-clamp
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scroll-on-drag 8962f5f8a7 30/35: Add scroll-on-drag-clamp option to prevent scrolling past point-max |
Date: |
Thu, 7 Jul 2022 12:02:52 -0400 (EDT) |
branch: elpa/scroll-on-drag
commit 8962f5f8a79c9178a577732ddfbb333a101bc7fc
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add scroll-on-drag-clamp option to prevent scrolling past point-max
---
readme.rst | 2 ++
scroll-on-drag.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/readme.rst b/readme.rst
index f26d2410c8..840b79fedb 100644
--- a/readme.rst
+++ b/readme.rst
@@ -75,6 +75,8 @@ While the defaults seem to work well, these values can be
customized.
``scroll-on-drag-smooth``: t
Smooth (pixel) scroll *(snapped to line on completion).*
+``scroll-on-drag-clamp``: nil
+ Prevent scrolling past the end of the buffer.
``scroll-on-drag-delay``: 0.01, typically in range [0.005 .. 0.1]
Time between scroll updates.
``scroll-on-drag-motion-scale``: 0.25, typically in range [0.01 .. 1.0]
diff --git a/scroll-on-drag.el b/scroll-on-drag.el
index 92e7805252..f0b80f9893 100644
--- a/scroll-on-drag.el
+++ b/scroll-on-drag.el
@@ -51,6 +51,8 @@
(defcustom scroll-on-drag-smooth t "Use smooth (pixel) scrolling." :type
'boolean)
+(defcustom scroll-on-drag-clamp nil "Prevent scrolling past the buffer end."
:type 'boolean)
+
(defcustom scroll-on-drag-follow-mouse t
"Scroll the window under the mouse cursor (instead of the current active
window)."
:type 'boolean)
@@ -187,6 +189,32 @@ Returns true when scrolling took place, otherwise nil."
(restore-window-start (window-start))
(restore-point (point))
+ ;; Don't move past the buffer end.
+ (point-clamp-max
+ (cond
+ (scroll-on-drag-clamp
+ (cond
+ ((eq (window-end) (point-max))
+ (line-beginning-position))
+ (t
+ (save-excursion
+ (goto-char (line-beginning-position))
+ (let
+ (
+ (lines
+ (-
+ (window-body-height)
+ ;; When the point is at the window top,
+ ;; account for it being clamped while scrolling.
+ (1+
+ (max
+ scroll-margin (count-lines restore-window-start
restore-point))))))
+ (goto-char (point-max))
+ (forward-line (- lines))
+ (point))))))
+ (t
+ nil)))
+
;; Restore indent (lost when scrolling).
(restore-column (current-column))
@@ -295,6 +323,27 @@ Returns true when scrolling took place, otherwise nil."
(scroll-on-drag--scroll-by-lines this-window lines t)
(setq do-draw t)))))
+ ;; Clamp the buffer inside the window.
+ (when point-clamp-max
+ ;; Scrolling down.
+ (when (< 0 delta)
+ (let
+ (
+ (scroll-pt
+ (cond
+ ((eq restore-point (point))
+ (line-beginning-position))
+ (t
+ (point)))))
+ (cond
+ ((= point-clamp-max scroll-pt)
+ (set-window-vscroll this-window 0 t))
+
+ ((< point-clamp-max scroll-pt)
+ (let ((lines (count-lines scroll-pt
point-clamp-max)))
+ (set-window-vscroll this-window 0 t)
+ (scroll-on-drag--scroll-by-lines this-window (-
lines) t)))))))
+
(when do-draw
(let ((inhibit-redisplay nil))
(run-hooks 'scroll-on-drag-redisplay-hook)
- [nongnu] elpa/scroll-on-drag fa6a293c74 14/35: Correct macro, (continued)
- [nongnu] elpa/scroll-on-drag fa6a293c74 14/35: Correct macro, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 81623ccc59 10/35: Add pre/post hooks, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag fb9af98461 34/35: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag d6257b2fb7 05/35: Prevent cursor changing over text, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 823aab7938 27/35: Cleanup: replace 'if' with 'cond', ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag be3c43b74e 21/35: Fix restoring the point with mixed tabs/spaces, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 3cd1e1801a 23/35: Update URL, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 2fbd643ea9 16/35: Add .elisp-autofmt to enable auto-formatting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 01c14f4c02 35/35: Cleanup: quiet checkdoc warning, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 0a362232a0 19/35: Run 'run-window-scroll-functions' after scrolling, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 8962f5f8a7 30/35: Add scroll-on-drag-clamp option to prevent scrolling past point-max,
ELPA Syncer <=
- [nongnu] elpa/scroll-on-drag 2d79a6d9c2 18/35: Cleanup: minor syntax changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 97741be699 32/35: Remove override for timer-idle-list, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag f9379c56df 03/35: Call redisplay explicitly, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 56ab51a329 07/35: Use zerop instead of comparing with zero, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 882dc94bb8 12/35: Cleanup: remove unused variables, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag cacadcd9bd 20/35: Cleanup: add sections, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 271b4aa6b3 11/35: Add redisplay hook, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 6d62a239a9 28/35: Cleanup: use defgroup, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag 6db1380826 25/35: Cleanup: formatting, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-drag ba2c1a598e 17/35: Fix for idle timers running during scroll, ELPA Syncer, 2022/07/07