all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Nathaniel Flath <flat0103@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Behaviour for save-excursion
Date: Tue, 06 Oct 2009 16:44:47 +0200	[thread overview]
Message-ID: <4ACB57DF.7040407@gmx.at> (raw)
In-Reply-To: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com>

 > 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




  reply	other threads:[~2009-10-06 14:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-06 13:44 Behaviour for save-excursion Nathaniel Flath
2009-10-06 14:44 ` martin rudalics [this message]
2009-10-06 14:48 ` Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ACB57DF.7040407@gmx.at \
    --to=rudalics@gmx.at \
    --cc=emacs-devel@gnu.org \
    --cc=flat0103@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.