Function: save-restriction

save-restriction is a special form defined in editfns.c.

Signature

(save-restriction &rest BODY)

Documentation

Execute BODY, saving and restoring current buffer's restrictions.

The buffer's restrictions make parts of the beginning and end invisible.
(They are set up with narrow-to-region and eliminated with widen.)
This special form, save-restriction, saves the current buffer's restrictions when it is entered, and restores them when it is exited. So any narrow-to-region within BODY lasts only until the end of the form. The old restrictions settings are restored even in case of abnormal exit (throw or error).

The value returned is the value of the last form in BODY.

Note: if you are using both save-excursion and save-restriction, use save-excursion outermost:
    (save-excursion (save-restriction ...))

Probably introduced at or before Emacs version 21.1.

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  register Lisp_Object val;
  ptrdiff_t count = SPECPDL_INDEX ();

  record_unwind_protect (save_restriction_restore, save_restriction_save ());
  val = Fprogn (body);
  return unbind_to (count, val);
}