Skip to main content
1 of 8
shynur
  • 5.9k
  • 1
  • 5
  • 28

Why write `save-excursion` OUTERMOST when write `save-excursion` and `save-restriction` together?

I'm reading Emacs Lisp Intro by Robert J. Chassell.

In 6.1 The ‘save-restriction’ Special Form

when you use both ‘save-excursion’ and ‘save-restriction’, one right after the other, you should use ‘save-excursion’ outermost. If you write them in reverse order, you may fail to record narrowing in the buffer to which Emacs switches after calling ‘save-excursion’.

And in 6.2 what-line

(Note that the ‘(widen)’ expression comes between the ‘save-restriction’ and ‘save-excursion’ special forms. When you write the two ‘save- ...’ expressions in sequence, write ‘save-excursion’ outermost.)

I'm really confused about why it should be written like this:

(save-excursion
  (save-restriction
    BODY...))

Any help is appreciated!

shynur
  • 5.9k
  • 1
  • 5
  • 28