[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behaviour for save-excursion

From: Chong Yidong
Subject: Re: Behaviour for save-excursion
Date: Tue, 06 Oct 2009 10:48:23 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Nathaniel Flath <address@hidden> writes:

> What is the proper behaviour for save-excursion?  The emacs-lisp intro
> and the docstring seem to have slightly differing explanations -
> namely, the docstring mentions that it saves current-buffer as well as
> point and mark, and the emacs-lisp intro does not.

The Lisp intro does say that it saves current-buffer:

     In addition to recording the values of point and mark,
  `save-excursion' keeps track of the current buffer, and restores it,

> Based on just what it does, I'm not entirely sure which is correct -
> the following code snippet, executed in *scratch*, returns the
> "*scratch*" buffer but the buffer displayed is the "bar" buffer, and
> evaluating current-bufer afterwards returns the "bar" buffer.

You shouldn't use switch-to-buffer in Lisp code unless you know what
you're doing.  That's why the docstring for switch-to-buffer has this:

  WARNING: This is NOT the way to work on another buffer temporarily
  within a Lisp program!  Use `set-buffer' instead.  That avoids
  messing with the window-buffer correspondences.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]