I used to set up the Emacs auto scrolling using the following lines, as someone online claimed this would result in “smooth scrolling”:
(setq scroll-margin 3
scroll-conservatively 10000)
However, when the cursor moves near the top or the bottom of the frame (or the window), Emacs automatically recenters and place the cursor in the middle of the screen. This has been bugging on me for too long. My personal preference of the cursor is: when I move it up or down near the screen top or bottom, I would like to have Emacs JUST MOVE 1 LINE for me, so I can follow naturally the movement of the cursor. If I need to recenter the screen and place the cursor in the middle, I would do it myself by calling C-l. I don’t need Emacs to move the cursor for me!
Today, after some searching, I finally figured out that the annoying jumping around of the Emacs cursor is due to the Automatic Scrolling of Emacs.
The idea of Automatic Scrolling, according to http://ecs.victoria.ac.nz/cgi-bin/info2www?(emacs)Auto+Scrolling, is:
“Redisplay scrolls the buffer automatically when point moves out of the visible portion of the text. The purpose of automatic scrolling is to make point visible, but YOU CAN CUSTOMIZE MANY ASPECTS OF HOW THIS IS DONE.”
There are four variables to be customize for the Automatic Scrolling feature of Emacs:
- scroll-margin: restricts how close point can come to the top or bottom of a window
- scroll-conservatively: if you set it to number N, then if you move point just a little off the screen–less than N lines–then Emacs scrolls the text just far enough to bring point back on screen
- scroll-up-aggressively: a number (F, meaning fraction) between 0 and 1, and it specifies where on the screen to put point when scrolling upward. More precisely, when a window scrolls up because point is above the window start, the new start position is chosen to put point F part of the window height from the top
- scroll-down-aggressively: a number (F, meaning fraction) between 0 and 1, and it specifies where on the screen to put point when scrolling downward. More precisely, when a window scrolls down because point is below the window bottom, the new start position is chosen to put point F part of the window height from the bottom
Based on these explanations, I configured my Automatic Scrolling according to my personal preference:
;; for smooth scrolling and disabling the automatical recentering of emacs when moving the cursor
(setq scroll-margin 1
scroll-conservatively 0
scroll-up-aggressively 0.01
scroll-down-aggressively 0.01)
Pingback: Interesting Emacs Links – 2009 Week 21 « A Curious Programmer
Yes, except that scroll-up-aggressively and scroll-down-aggressively are buffer-local and need to be set by setq-default
setq-default scroll-up-aggressively 0.01
scroll-down-aggressively 0.01)
Thus, I’m not sure why the above worked for you. Maybe it was the scroll-margin (I don’t use that).
Thanks! You saved my day!
Carlos
Very glad to hear that!
Thanks for the comments!
Thanks for the guide!
However, it was a bit weird. Setting scroll-up-aggressively fixes smooth scrolling when moving the cursor DOWNWARDS (!) and setting scroll-down-aggressively fixes smooth scrolling when moving the cursor UPWARDS. :-D
Those two were the only options I needed to set (scroll-conservatively was 0 as default, scroll-margin just changed the scroll margin as expected).
Thanks so much!
I’ve just started trying out emacs and this scroll/jump problem was looking like a deal-breaker.
LOL
use (setq scroll-step 1)
Using the settings listed above did not work for me. However, setting scroll-conservatively to 2000 did.
A motivating discussion is definitely worth comment. There’s no doubt that that you ought to publish more on this issue, it might not be a taboo subject but usually people don’t discuss such issues.
To the next! Kind regards!!