Chapter 7. Minor Mode
In this chapter we’ll ratchet our Emacs programming dexterity up a notch by considering times when we don’t want extensions to apply to all buffers, but just to a particular type of buffer. For instance, when you’re in Lisp mode it’s nice to press C-M-a and have Emacs jump backwards to the beginning of the nearest function definition, but you don’t want or need that ability when you’re editing a textual document. The Emacs “mode” mechanism arranges things so that C-M-a does its magic only when you’re in Lisp mode.
The subject of modes in Emacs is a complex one. We’ll ease into it by first studying so-called minor modes. A minor mode coexists with a major mode in a buffer, adding a typically small amount of new editing behavior. Every Emacs user is familiar with major modes like Lisp and C and Text, but they may not be aware of little strings that appear on the “mode line” saying things like Fill when you’re also in Auto Fill minor mode.
We’ll create a minor mode that builds on Emacs’s idea of filling paragraphs. Our minor mode, Refill, dynamically fills paragraphs as you edit them.
Filling a paragraph is the process of making all the lines in the paragraph the right length. Every line should be more or less equally long without extending past the right margin. Long lines should be split up at the spaces between words. Short lines should be lengthened with text from subsequent ...