help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Minimizing automatic scrolling


From: Psionic K
Subject: Minimizing automatic scrolling
Date: Sun, 12 Nov 2023 22:53:32 +0900

I cannot find an option to disable all automatic scrolling caused by
minibuffer setup or transient setup.  I devised a solution that illustrates
the issue I'm managing:

    ;; Auto-scroll as little as possible.  Avoid moving the point.
    ;; Firstly, dynamically set `scroll-conservatively' to avoid automatic
re-centers.
    ;; We want automatic re-center when swiper for example goes off screen,
but for
    ;; minibuffer or transient display, we want the minimum possible scroll.
    ;; And finally, dynamically shrink the margin so that the space created
by
    ;; margin will all be used up before automatic scrolling can occur and
margins
    ;; will not be maintained during minibuffer or transient display.
    (defvar pmx--no-herky-jerk-margin nil)
    (defvar pmx--no-herky-jerk-scroll-conservatively nil)
    (setq scroll-margin 12) ; larger than ivy size, eliminating most scrolls
    (defun pmx--no-herky-jerk-enter (&rest _)
      "Shrinks margin."
      (setq pmx--no-herky-jerk-scroll-conservatively scroll-conservatively)
      (setq scroll-conservatively 101)
      (setq pmx--no-herky-jerk-margin scroll-margin)
      (setq scroll-margin 0))

    (defun pmx--no-herky-jerk-exit ()
      "Expands margin."
      (when pmx--no-herky-jerk-scroll-conservatively
        (setq scroll-conservatively
pmx--no-herky-jerk-scroll-conservatively))
      (setq pmx--no-herky-jerk-scroll-conservatively nil)
      (when pmx--no-herky-jerk-margin
        (setq scroll-margin pmx--no-herky-jerk-margin))
      (setq pmx--no-herky-jerk-margin nil))

    (add-hook 'minibuffer-setup-hook #'pmx--no-herky-jerk-enter)
    (add-hook 'minibuffer-exit-hook #'pmx--no-herky-jerk-exit)

    ;; Add the same for transient
    (with-eval-after-load 'transient
      (advice-add 'transient-setup :before #'pmx--no-herky-jerk-enter)
      (add-hook 'transient-exit-hook #'pmx--no-herky-jerk-exit)
      (setopt transient-hide-during-minibuffer-read t))

Happy to work on a patch if one is needed.

I also noticed that transient's default side-window display has a very
desirable property of only triggering scrolling once and then leaving the
window in a state where it won't scroll during the next transient display.
The minibuffer cleans up its scrolling, causing repeated "herky-jerk"
events.

I believe we need two options.  The first should be to not automatically
scroll unselected windows during resize.  The second should be to retain
scrolls caused by minibuffer expansion.

>From what I have gathered, the window data model doesn't have a way to
express the idea that a window is temporary, so packages can't advertise to
Emacs that they are intended for temporary focused usage.

On focus, a window should scroll if appropriate, helping to visually
indicate that a window has become selected and fix the mis-indication that
a buffer has become selected and received unintended commands when a resize
has occurred.  Having an option to simply not auto scroll during resize
when not selected and another option to preserve scrolls caused by
minibuffer expansion would allow near perfect behavior.

-- 

남백호
대표 겸 공동 창업자
포지트론


reply via email to

[Prev in Thread] Current Thread [Next in Thread]