Chapter 8. Evaluation and Error Recovery

In the previous chapter, we noted that save-excursion is a moderately expensive function, and we tried to reduce the number of times it is called in refill (which, since it’s invoked on every buffer change, needs to be as fast as possible). Nevertheless, the code for refill contains five calls to save-excursion.

We could try to coalesce the uses of save-excursion—for example, by surrounding the entire body of refill with a call to save-excursion, discarding all the save-excursions within, and rewriting everything else to make sure the cursor is properly positioned at all times. But this would harm the clear layout of the code. Of course, clarity does sometimes have to be sacrificed in the name of optimization, but before we consider coalescing the calls to save-excursion, let’s see if we can do without them. It turns out we can replace them with a different function with less overhead.

In this chapter we will explore ways to write a faster, limited form of save-excursion. We’ll encounter many interesting features of Emacs that have a common purpose: to control when things are evaluated and what effect they have on the surrounding code. We will be considering such issues as return values and cleaning up in case of error. We’ll see how you can make the Lisp interpreter refrain from evaluating expressions until you are ready ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.