Go to the first, previous, next, last section, table of contents.


Hooks for Vertical Scrolling

This section describes how a Lisp program can take action whenever a window displays a different part of its buffer or a different buffer. There are three actions that can change this: scrolling the window, switching buffers in the window, and changing the size of the window. The first two actions run window-scroll-functions; the last runs window-size-change-functions. The paradigmatic use of these hooks is Lazy Lock mode; see section `Font Lock Support Modes' in The GNU Emacs Manual.

Variable: window-scroll-functions
This variable holds a list of functions that Emacs should call before redisplaying a window with scrolling. It is not a normal hook, because each function is called with two arguments: the window, and its new display-start position.

Displaying a different buffer in the window also runs these functions.

These functions cannot expect window-end (see section The Window Start Position) to return a meaningful value, because that value is updated only by redisplaying the buffer. So if one of these functions needs to know the last character that will fit in the window with its current display-start position, it has to find that character using vertical-motion (see section Motion by Screen Lines).

Variable: window-size-change-functions
This variable holds a list of functions to be called if the size of any window changes for any reason. The functions are called just once per redisplay, and just once for each frame on which size changes have occurred.

Each function receives the frame as its sole argument. There is no direct way to find out which windows on that frame have changed size, or precisely how. However, if a size-change function records, at each call, the existing windows and their sizes, it can also compare the present sizes and the previous sizes.

Creating or deleting windows counts as a size change, and therefore causes these functions to be called. Changing the frame size also counts, because it changes the sizes of the existing windows.

It is not a good idea to use save-window-excursion (see section Window Configurations) in these functions, because that always counts as a size change, and it would cause these functions to be called over and over. In most cases, save-selected-window (see section Selecting Windows) is what you need here.


Go to the first, previous, next, last section, table of contents.