1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Allow interpolating scrolls via the Page Down and Page Up keys

* 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.
This commit is contained in:
Po Lu 2021-12-26 10:36:05 +08:00
parent ab3d5b8b32
commit bb666073d3

View 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.