1

I want Emacs to scroll on [up] and [down] cursor keys one line at a time.

I have already installed and checked out following packages:

  • smooth-scroll
  • smooth-scrolling
  • good-scroll

Only smooth-scrolling works, but while scrolling down it starts sometimes to jump instead of scrolling by one line.

Is it possible to have a bug-free smooth scrolling one line at a time in Emacs?

How?

P.S. I can't reliably reproduce the problem with the jumps by multiple lines. It occurs preferably in windows with a small number of lines, but sometimes it works OK when only three lines are visible.

Sometimes the position of the point (cursor) changes up and down and this seem to depend on the length of the line and occurs preferably near very long lines (for example 250 chars). This behavior appears to be reproducible, so you can check it out yourself if you are using the smooth-scrolling package.

Claudio
  • 410
  • 2
  • 11
  • 1
    How about trying `(setq scroll-conservatively 101)` without any other scroll settings. Most of the old examples combine that setting with other stuff, but I suggest not doing that. To read the doc-string, type `C-h v` aka `M-x describe-variable` – lawlist Mar 28 '23 at 15:32
  • 1
    @lawlist : if you provide this hint as answer I will accept it. It's worth to have it mentioned here on emacs.stackexchange, so it can be found as answer. – Claudio Mar 28 '23 at 17:23
  • 1
    I deleted my second comment because after re-reading the doc-string, it *does* answer your question as to a value of "101 or 1 or 10 or 120". ... Because 101 and 120 are both greater than 100, they have the same affect; i.e., "*redisplay will never recenter point, but will always scroll just enough text to bring point into view, even if you move far away*". A value of 1 or 10 (which are less than or equal to 100), means "*[s]croll up to this many lines, to bring point back on screen. If point moves off-screen, redisplay will scroll by up to `scroll-conservatively` lines in order to ...*". – lawlist Mar 28 '23 at 22:17
  • What try the explanations to say? How can I experience different behavior specifying different values? – Claudio Mar 28 '23 at 22:31
  • Anyone here who can confirm moving the position of the point (cursor) while scrolling over very long lines while using `smooth-scrolling`? Or confirm unpredictable behavior of smooth-scrolling I am speaking about mentioning jumping? – Claudio Mar 28 '23 at 22:33
  • "*it starts sometimes to jump*" --- You can try to see if their source code mentions the variable `scroll-step`; if so, the case you're talking about may be caused by [a bug that I just fixed today](https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-03/msg01835.html). BTW, `scroll-conservatively` does have some weird behaviors with some themes enabled (and I still don't know why). But, actually, I still don't know the specific behavior of the bug you described, it would be nice to post a GIF. – shynur Mar 30 '23 at 07:51
  • Yes, a GIF were nice. I have still no idea how to easily make a gif from a sequence of screenshots controlling the timing between the frames. I have a screenkey app showing the pressed keys (maybe you can respond to me via our chat? In order to not pollute this here with unrelated comments? – Claudio Mar 30 '23 at 10:51
  • By the way: my time-budget for fixing the scrolling trouble is currently almost exhausted. I can live and arrange me with it or use `scroll-conservatively`. – Claudio Mar 30 '23 at 10:57

1 Answers1

1

Is it possible to have a bug-free smooth scrolling one line at a time in Emacs? How?

Instead of using (prone to bugs) packages use the built-in scroll-conservatively and set its value to 101 in your .emacs (or other init) file:

(setq scroll-conservatively 101)

( Check out C-h o -> scroll-conservatively` for info about why 101 )

Below a proposal of code which scrolls smooth line by line keeping the cursor/point usually (on wrapped lines it doesn't) in the same line near the center of the window. With the additional keybindings for M-<up> and M-<down> it is possible to 'stay' at the cursor keys while vertically repositioning the point on the screen:

;; ---------------------------------------------------------------------
;; Scroll with <up><down> one line at a time keeping the cursor/point 
;; always at the same line near the center of the window: 
(global-set-key (kbd "<down>") (lambda (&optional ARG TRY-VSCROLL) (interactive "^p\nP") (next-line     ARG TRY-VSCROLL) (recenter)))
(global-set-key (kbd "<up>")   (lambda (&optional ARG TRY-VSCROLL) (interactive "^p\nP") (previous-line ARG TRY-VSCROLL) (recenter)))
(global-set-key (kbd "M-<up>"  ) 'previous-line)
(global-set-key (kbd "M-<down>") 'next-line)

You can put the above code into your .emacs file and enjoy the new navigation feature, but ...

... be warned that it was not extensively tested, so there is a chance that in some edge cases it does not work as expected.

Anyway in the preliminary tests these four lines of code worked better than the for smooth scrolling available packages.

Thanks goes to @Shynur for providing the core of the code used above.


Notice that the code above in combination with the follow-mode provides the feature of keeping the cursor/point in one of the multiple windows.

Claudio
  • 410
  • 2
  • 11