[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Behaviour for save-excursion
From: |
martin rudalics |
Subject: |
Re: Behaviour for save-excursion |
Date: |
Tue, 06 Oct 2009 16:44:47 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Windows/20090302) |
> 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. 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.
>
> (progn
> (save-excursion
> (switch-to-buffer "bar"))
> (current-buffer))
>
> Either the manual or the docstring should be changed to reflect what it
> does, but I'm not entirely sure which based on this.
Please read the Elisp manual entry on `save-excursion' which states:
Likewise, `save-excursion' does not restore window-buffer
correspondences altered by functions such as `switch-to-buffer'.
One way to restore these correspondences, and the selected window,
is to use `save-window-excursion' inside `save-excursion' (*note
Window Configurations::).
Also the following entry from section 27.2 The Current Buffer of the
Elisp manual might provide further explanation:
When an editing command returns to the editor command loop, the
command loop designates the buffer displayed in the selected window as
current, to prevent confusion: the buffer that the cursor is in when
Emacs reads a command is the buffer that the command will apply to.
(*Note Command Loop::.) Therefore, `set-buffer' is not the way to
switch visibly to a different buffer so that the user can edit it. For
that, you must use the functions described in *Note Displaying
Buffers::.
martin