Line-at-a-Time Scrolling

Before I became an Emacs user, I grew accustomed to some functions in other editors that weren't present in Emacs. Naturally I missed having those functions and decided to replace them. One example is the ability to scroll text up and down one line at a time with a single keystroke.

Emacs has two scrolling functions, scroll-up and scroll-down, which are bound to C-v and M-v. Each function takes an optional argument telling it how many lines to scroll. By default, they each scroll the text one windowful at a time. (Don't confuse scrolling up and down with moving the cursor up and down as with C-n and C-p. Cursor motion moves the cursor and scrolls the text only if necessary. Scrolling moves the text in the window and moves the cursor only if necessary.)

Though I could scroll up and down one line at a time with C-u 1 C-v and C-u 1 M-v, I wanted to be able to do it with a single keystroke. Using the techniques from the previous section, it is easy to write two new commands for scrolling with one keystroke.

First things first, though. I can never remember which function does what. Does scroll-up mean that the text moves up, revealing parts of the file that are farther down? Or does it mean that we reveal parts of the file that are farther up, moving the text down? I'd prefer that these functions had less confusing names, like scroll-ahead and scroll-behind.

We can use defalias to refer to any Lisp function by a different name.

(defalias 'scroll-ahead 'scroll-up) ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.