all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
To: Nathaniel Flath <flat0103@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Behaviour for save-excursion
Date: Tue, 06 Oct 2009 10:48:23 -0400	[thread overview]
Message-ID: <87eipg1sug.fsf@stupidchicken.com> (raw)
In-Reply-To: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com> (Nathaniel Flath's message of "Tue, 6 Oct 2009 09:44:38 -0400")

Nathaniel Flath <flat0103@gmail.com> 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,
  too.


> 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.




      parent reply	other threads:[~2009-10-06 14:48 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
2009-10-06 14:48 ` Chong Yidong [this message]

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=87eipg1sug.fsf@stupidchicken.com \
    --to=cyd@stupidchicken.com \
    --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.