Track scroll-conservatively per-buffer to avoid clobbering local values#45
Open
brettatoms wants to merge 1 commit into
Open
Track scroll-conservatively per-buffer to avoid clobbering local values#45brettatoms wants to merge 1 commit into
brettatoms wants to merge 1 commit into
Conversation
ultra-scroll raises `scroll-conservatively' to 101 during a scroll and restores the prior value on idle, but tracked the saved value globally. Since `scroll-conservatively' can be buffer-local (some modes pin it >=100), this leaks across buffers: a scroll in a <100 buffer saves that low value, then a scroll in a >=100 buffer skips the save but still runs the restore, clobbering its local setting. Once lowered, a redisplay with point off-screen recenters, causing a large jump. Make the saved value buffer-local and use nil for "not raised here", so the restore only fires when this buffer's value was actually raised.
Owner
|
Thanks. Can you test this in scenarios where the same buffer is shown in multiple windows and the non-active window gets scrolled? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ultra-scroll raises
scroll-conservativelyto 101 during a scroll and restores the prior value on idle, tracking the saved value in a global variable (ultra-scroll--scroll-conservatively-orig).scroll-conservativelycan be set buffer-locally, and some modes set it to >=100 on purpose. Tracking the saved value globally leaks it across buffers:scroll-conservativelyis <100 (e.g. the global default).--prepare-to-scrollsaves that low value and raises to 101.scroll-conservativelyis >=100.--prepare-to-scrollskips the save (nothing to raise), but--end-scrollstill runs the restore and writes the stale low value into this buffer, overwriting its buffer-local >=100 setting.Once lowered, a forced redisplay while point is off-screen makes Emacs recenter, yanking the window by a large amount.
I hit this with the ghostel terminal emulator, which sets
scroll-conservativelyto 101 buffer-locally so its decoupled point does not trigger a recenter. After scrolling a normal buffer and then the terminal, the terminal's value was reset to the global default, and the next redraw (a spinner timer) jumped the window several pages toward the top.Fix
Make
ultra-scroll--scroll-conservatively-origbuffer-local and use nil to mean "not raised in this buffer", so--end-scrollonly restores when this buffer's value was actually raised. The save in--prepare-to-scrollalready only runs when the value is <100, so it doubles as the sentinel. The seed in the mode-enable body is no longer needed and is removed.Testing
emacs -Q: a <100 buffer is raised to 101 during scroll and restored after; a >=100 buffer is left untouched with no nil-comparison error; a >=100 buffer is not affected by a prior scroll in a <100 buffer.