Da's recipes on Emacs, IT, and more

Customize Emacs Automatic Scrolling, and stop the cursor from jumping around as I move it

Advertisements

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:

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)

Advertisements

Advertisements