14.3 Automatic Scrolling
Emacs performs automatic scrolling when point moves out of the visible portion of the text. Normally, automatic scrolling centers point vertically in the window, but there are several ways to alter this behavior.
If you set scroll-conservatively
to a small number n
, then moving point just a little off the screen (no more than n
lines) causes Emacs to scroll just enough to bring point back on screen; if doing so fails to make point visible, Emacs scrolls just far enough to center point in the window. If you set scroll-conservatively
to a large number (larger than 100), automatic scrolling never centers point, no matter how far point moves; Emacs always scrolls text just enough to bring point into view, either at the top or bottom of the window depending on the scroll direction. By default, scroll-conservatively
isย 0, which means to always center point in the window.
Another way to control automatic scrolling is to customize the variable scroll-step
. Its value determines the number of lines by which to automatically scroll, when point moves off the screen. If scrolling by that number of lines fails to bring point back into view, point is centered instead. The default value is zero, which (by default) causes point to always be centered after scrolling.
A third way to control automatic scrolling is to customize the variables scroll-up-aggressively
and scroll-down-aggressively
, which directly specify the vertical position of point after scrolling. The value of scroll-up-aggressively
should be either nil
(the default), or a floating point number f
between 0 and 1. The latter means that when point goes below the bottom window edge (i.e., scrolling forward), Emacs scrolls the window so that point is f
parts of the window height from the bottom window edge. Thus, larger f
means more aggressive scrolling: more new text is brought into view. The default value, nil
, is equivalent to 0.5.
Likewise, scroll-down-aggressively
is used when point goes above the top window edge (i.e., scrolling backward). The value specifies how far point should be from the top margin of the window after scrolling. Thus, as with scroll-up-aggressively
, a larger value is more aggressive.
Note that the variables scroll-conservatively
, scroll-step
, and scroll-up-aggressively
/ scroll-down-aggressively
control automatic scrolling in contradictory ways. Therefore, you should pick no more than one of these methods to customize automatic scrolling. In case you customize multiple variables, the order of priority is: scroll-conservatively
, then scroll-step
, and finally scroll-up-aggressively
/ scroll-down-aggressively
.
The variable scroll-margin
restricts how close point can come to the top or bottom of a window (even if aggressive scrolling specifies a fraction f
that is larger than the window portion between the top and the bottom margins). Its value is a number of screen lines; if point comes within that many lines of the top or bottom of the window, Emacs performs automatic scrolling. By default, scroll-margin
is 0. The effective margin size is limited to a quarter of the window height by default, but this limit can be increased up to half (or decreased down to zero) by customizing maximum-scroll-margin
.