Function: save-excursion

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

Signature

(save-excursion &rest BODY)

Documentation

Save point, and current buffer; execute BODY; restore those things.

Executes BODY just like progn. The values of point and the current buffer are restored even in case of abnormal exit (throw or error).

If you only want to save the current buffer but not point, then just use save-current-buffer, or even with-current-buffer.

Before Emacs 25.1, save-excursion used to save the mark state. To save the mark state as well as point and the current buffer, use save-mark-and-excursion.

View in manual

Probably introduced at or before Emacs version 20.1.

Source Code

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

  record_unwind_protect_excursion ();

  val = Fprogn (args);
  return unbind_to (count, val);
}