]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow interpolating scrolls via the Page Down and Page Up keys
authorPo Lu <luangruo@yahoo.com>
Sun, 26 Dec 2021 02:36:05 +0000 (10:36 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 26 Dec 2021 02:36:05 +0000 (10:36 +0800)
* lisp/pixel-scroll.el (pixel-scroll-precision-mode-map): Define
new commands.
(pixel-scroll-precision-interpolate-page): New user option.
(pixel-scroll-interpolate-down):
(pixel-scroll-interpolate-up): New functions.

lisp/pixel-scroll.el

index b943365a3f59fa4180c6eef4583a4ea9bc499a9b..3abd4b2a723e143cec758231c301fc2fdf421439 100644 (file)
@@ -96,30 +96,32 @@ is always with pixel resolution.")
 
 (defvar pixel-scroll-precision-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [wheel-down] #'pixel-scroll-precision)
-    (define-key map [wheel-up] #'pixel-scroll-precision)
-    (define-key map [touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [mode-line wheel-down] #'pixel-scroll-precision)
-    (define-key map [mode-line wheel-up] #'pixel-scroll-precision)
-    (define-key map [mode-line touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [header-line wheel-down] #'pixel-scroll-precision)
-    (define-key map [header-line wheel-up] #'pixel-scroll-precision)
-    (define-key map [header-line touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [vertical-scroll-bar wheel-down] #'pixel-scroll-precision)
-    (define-key map [vertical-scroll-bar wheel-up] #'pixel-scroll-precision)
-    (define-key map [vertical-scroll-bar touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [left-margin wheel-down] #'pixel-scroll-precision)
-    (define-key map [left-margin wheel-up] #'pixel-scroll-precision)
-    (define-key map [left-margin touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [right-margin wheel-down] #'pixel-scroll-precision)
-    (define-key map [right-margin wheel-up] #'pixel-scroll-precision)
-    (define-key map [right-margin touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [left-fringe wheel-down] #'pixel-scroll-precision)
-    (define-key map [left-fringe wheel-up] #'pixel-scroll-precision)
-    (define-key map [left-fringe touch-end] #'pixel-scroll-start-momentum)
-    (define-key map [right-fringe wheel-down] #'pixel-scroll-precision)
-    (define-key map [right-fringe wheel-up] #'pixel-scroll-precision)
-    (define-key map [right-fringe touch-end] #'pixel-scroll-start-momentum)
+    (define-key map [wheel-down] 'pixel-scroll-precision)
+    (define-key map [wheel-up] 'pixel-scroll-precision)
+    (define-key map [touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [mode-line wheel-down] 'pixel-scroll-precision)
+    (define-key map [mode-line wheel-up] 'pixel-scroll-precision)
+    (define-key map [mode-line touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [header-line wheel-down] 'pixel-scroll-precision)
+    (define-key map [header-line wheel-up] 'pixel-scroll-precision)
+    (define-key map [header-line touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [vertical-scroll-bar wheel-down] 'pixel-scroll-precision)
+    (define-key map [vertical-scroll-bar wheel-up] 'pixel-scroll-precision)
+    (define-key map [vertical-scroll-bar touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [left-margin wheel-down] 'pixel-scroll-precision)
+    (define-key map [left-margin wheel-up] 'pixel-scroll-precision)
+    (define-key map [left-margin touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [right-margin wheel-down] 'pixel-scroll-precision)
+    (define-key map [right-margin wheel-up] 'pixel-scroll-precision)
+    (define-key map [right-margin touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [left-fringe wheel-down] 'pixel-scroll-precision)
+    (define-key map [left-fringe wheel-up] 'pixel-scroll-precision)
+    (define-key map [left-fringe touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [right-fringe wheel-down] 'pixel-scroll-precision)
+    (define-key map [right-fringe wheel-up] 'pixel-scroll-precision)
+    (define-key map [right-fringe touch-end] 'pixel-scroll-start-momentum)
+    (define-key map [next] 'pixel-scroll-interpolate-down)
+    (define-key map [prior] 'pixel-scroll-interpolate-up)
     map)
   "The key map used by `pixel-scroll-precision-mode'.")
 
@@ -180,6 +182,13 @@ Nil means to not interpolate such scrolls."
   :type 'float
   :version "29.1")
 
+(defcustom pixel-scroll-precision-interpolate-page nil
+  "Whether or not to interpolate scrolling via the Page Down and Page Up keys.
+This is only effective when `pixel-scroll-precision-mode' is enabled."
+  :group 'scrolling
+  :type 'boolean
+  :version "29.1")
+
 (defun pixel-scroll-in-rush-p ()
   "Return non-nil if next scroll should be non-smooth.
 When scrolling request is delivered soon after the previous one,
@@ -751,6 +760,20 @@ It is a vector of the form [ VELOCITY TIME ]."
               (aset state 0 (make-ring 10))
               (aset state 1 nil))))))))
 
+(defun pixel-scroll-interpolate-down ()
+  "Interpolate a scroll downwards by one page."
+  (interactive)
+  (if pixel-scroll-precision-interpolate-page
+      (pixel-scroll-precision-interpolate (- (window-text-height nil t)))
+    (scroll-up)))
+
+(defun pixel-scroll-interpolate-up ()
+  "Interpolate a scroll upwards by one page."
+  (interactive)
+  (if pixel-scroll-precision-interpolate-page
+      (pixel-scroll-precision-interpolate (window-text-height nil t))
+    (scroll-down)))
+
 ;;;###autoload
 (define-minor-mode pixel-scroll-precision-mode
   "Toggle pixel scrolling.