Narrowing

You may already be familiar with the Emacs concept of narrowing. It is possible to define a region of a buffer and narrow the buffer to that region. Emacs then makes it appear that that region is the entire buffer, hiding any text that comes before or after it. All editing operations, and most Lisp functions, are confined to the narrowed region (although when the file is saved, all of it is saved regardless of any narrowing) until the user undoes the narrowing with widen, normally bound to C-x n w.[39] So narrow-to-quip satisfies the requirement, "It should allow the user to restrict editing operations to a single quip."

Emacs Lisp code must be written to be aware of the possibility that a buffer is narrowed. Most of the time, Lisp functions won't care. They can behave as if the narrowed portion is the whole buffer. Some functions that normally deal with buffer boundaries actually deal with narrowed-region boundaries when narrowing is in effect. For instance, eobp ("end-of-buffer-p"), which normally tests whether point is at the end of the buffer, returns true if point is at the end of a narrowed region. Similarly, point-min and point-max return the boundaries of the narrowed region if there is one, not of the whole buffer. In a sense, these functions are preserving a fiction for the benefit of Lisp programmers, who might otherwise have to go to extreme lengths to keep all their code aware of the possibility of narrowing.

There is a price to pay, however. On some occasions, ...

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.