Quip Commands

What else should Quip mode be able to do?

  • It should allow the user to move forward and backward a quip at a time.

  • It should allow the user to restrict editing operations to a single quip.

  • It should be able to report the number of quips in the file, and the number of the quip that point is on.

  • Apart from that, it should work by and large the same way Text mode works. After all, the contents are mostly plain text.

Let's pause a moment to consider the different kinds of cursor motion commands in Emacs. There's forward-char and backward-char for moving one character at a time. There's forward-word and backward-word. There's forward-line and previous-line. There are also commands for moving forward and backward in units of sentences, paragraphs, sexps, and pages.

What's a page? Conventionally, a new page begins at a formfeed character (control-L), because in the ancient days of teletypes and line printers, the way to begin a new page was to send a control-L to the device. In true Emacs style, however, we can redefine what constitutes a "page" by changing the regexp in page-delimiter.

(make-local-variable 'page-delimiter)
(setq page-delimiter "^%%$")

This single insight—making a "page" equal a "quip"—solves most of the requirements we've stipulated for Quip mode! Now Emacs's many built-in page commands will operate on quips:

  • backward-page and forward-page, normally bound to C-x [ and C-x ], allow moving back and forth a quip at a time

  • narrow-to-page, bound to C-x n p, confines ...

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.