feat(smooth-scroll): add +interpolate flag

Adds optional scroll interpolation/animation in #8335 via the
good-scroll package. Command support is light right now, but I plan to
expand on it later, and I welcome PRs to do so in the meantime.

Ref: #8335
This commit is contained in:
Henrik Lissner
2025-04-03 17:26:48 -04:00
parent 46742977b1
commit 318e630037
3 changed files with 43 additions and 7 deletions

View File

@ -4,18 +4,21 @@
#+since: 25.05.0
* Description :unfold:
This module activates OS-independent smooth scrolling in Emacs. This primarily
benefits trackpad and scroll wheel users (not so much those that scroll via
their keyboards), by utilizing the [[https://github.com/jdtsmith/ultra-scroll][ultra-scroll]] package.
This module enables multiple kinds of smooth scrolling in Emacs. Its primary
function is to make input scrolling (on trackpads and scroll wheels)
pixel-smooth. With the =+interpolate= flag, it performs interpolated scrolling on
a growing list of scroll commands that traverse larger distances, smoothly
scrolling from point A to B on PgUp or PgDown (or [[kbd:][C-d]]/[[kbd:][C-u]] for Evil users).
#+begin_quote
 This module requires Emacs 29.1 or newer.
#+end_quote
#+begin_quote
For optimal performance from this module, it's highly recommended you use
Emacs with native-compilation. MacOS users may also have a better experience
using the [[https://bitbucket.org/mituharu/emacs-mac][emacs-mac]] fork of Emacs, available via Homebrew.
Scroll interpolation support is currently limited to the ~scroll-up~ and
~scroll-down~ commands, and any command that calls them (like ~evil-scroll-down~
and ~evil-scroll-up~), so you're likely to find many scroll commands are not
interpolated. We welcome PRs to expand its support.
#+end_quote
** Maintainers
@ -24,10 +27,14 @@ their keyboards), by utilizing the [[https://github.com/jdtsmith/ultra-scroll][u
[[doom-contrib-maintainer:][Become a maintainer?]]
** Module flags
/This module has no flags./
- +interpolate ::
Enables scroll interpolation for some larger-step scrolling commands. E.g.
PgUp and PgDown (or C-d/C-u for Evil users) will now smoothly scroll to its
destination rather than jump to it.
** Packages
- [[doom-package:ultra-scroll]]
- [[doom-package:good-scroll]] if [[doom-module:+interpolate]]
** Hacks
/No hacks documented for this module./
@ -41,6 +48,12 @@ their keyboards), by utilizing the [[https://github.com/jdtsmith/ultra-scroll][u
/This module has no external requirements./
#+begin_quote
 For optimal performance from this module, it's highly recommended you use
Emacs with native-compilation. MacOS users may also have a better experience
using the [[https://bitbucket.org/mituharu/emacs-mac][emacs-mac]] fork of Emacs, available via Homebrew.
#+end_quote
* Usage
This module only needs to be activated to experience its benefits.

View File

@ -11,3 +11,23 @@
(add-hook 'ultra-scroll-hide-functions #'hl-todo-mode)
(add-hook 'ultra-scroll-hide-functions #'diff-hl-flydiff-mode)
(add-hook 'ultra-scroll-hide-functions #'jit-lock-mode))
(use-package good-scroll
:when (modulep! +interpolate)
:hook (doom-first-input . good-scroll-mode)
:config
(defun good-scroll--convert-line-to-step (line)
(cond ((integerp line) (* line (line-pixel-height)))
((or (null line) (memq '- line))
(- (good-scroll--window-usable-height)
(* next-screen-context-lines (line-pixel-height))))
((line-pixel-height))))
(defadvice! good-scroll--scroll-up (&optional arg)
:override #'scroll-up
(good-scroll-move (good-scroll--convert-line-to-step arg)))
(defadvice! good-scroll--scroll-down (&optional arg)
:override #'scroll-down
(good-scroll-move (- (good-scroll--convert-line-to-step arg)))))

View File

@ -4,3 +4,6 @@
(package! ultra-scroll
:recipe (:host github :repo "jdtsmith/ultra-scroll")
:pin "b72c507f6702db18d971a6b6bdc692e260f21159")
(when (modulep! +interpolate)
(package! good-scroll :pin "a7ffd5c0e5935cebd545a0570f64949077f71ee3"))