From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: save-current-buffer
Date: Tue, 21 Oct 2008 13:26:35 +0200 [thread overview]
Message-ID: <1224588747.694138@arno.fh-trier.de> (raw)
In-Reply-To: <mailman.1511.1224431046.25473.help-gnu-emacs@gnu.org>
Nikolaj Schumacher wrote:
> Andreas Politz <politza@fh-trier.de> wrote:
>
>> Is this a bug, or am I missing something ?
>> Eval this in *scratch* buffer and you end up in the *Help* one.
>>
>> (save-current-buffer
>> (switch-to-buffer "*Help*"))
>
> There is a subtle difference between the current-buffer and the window's
> buffer. Any buffer can be current without being displayed. The
> function for that is `set-buffer'.
>
> `switch-to-buffer' changes both the current-buffer and the selected window's
> buffer.
>
> (progn
> (message "%s/%s" (current-buffer) (window-buffer (selected-window)))
> (save-current-buffer
> (switch-to-buffer "*Help*")
> (message "%s/%s" (current-buffer) (window-buffer (selected-window))))
> (message "%s/%s" (current-buffer) (window-buffer (selected-window))))
>
> will output:
>
> *scratch*/*scratch*
> *Help*/*Help*
> *scratch*/*Help*
>
> As you can see, current-buffer is restored, but the window's
> buffer is not.
>
> Replacing `save-current-buffer' with `save-window-excursion'
>
> gets you:
>
> *scratch*/*scratch*
> *Help*/*Help*
> *scratch*/*scratch*
>
>
> But generally, `switch-to-buffer' should only be used when the user
> wants to see the new buffer. Otherwise `set-buffer' is the better choice.
>
>
>
> regards,
> Nikolaj Schumacher
>
>
I see. I assume after the form is evaluated, some event will set the current-buffer
to the one switch-to-buffer switched to.
The reason I was asking is some problem I had with the recentf package. It's
really a minor one, but I was just curious what to make of it and how things are working.
The idiom from above is used in one of it's functions.
(require 'recentf)
(run-with-timer 0 nil 'recentf-open-files)
Now pressing 'q' gives a read-only error, though it is
bound to recentf-cancel-dialog. Pressing it twice works fine.
-ap
next prev parent reply other threads:[~2008-10-21 11:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-18 20:43 save-current-buffer Andreas Politz
2008-10-18 23:12 ` save-current-buffer B. T. Raven
2008-10-19 2:57 ` save-current-buffer Chris F.A. Johnson
2008-10-20 0:37 ` save-current-buffer B. T. Raven
2008-10-19 7:24 ` save-current-buffer Glauber Alex Dias Prado
[not found] ` <mailman.1486.1224401134.25473.help-gnu-emacs@gnu.org>
2008-10-19 10:31 ` save-current-buffer Andreas Politz
2008-10-19 15:44 ` save-current-buffer Nikolaj Schumacher
[not found] ` <mailman.1511.1224431046.25473.help-gnu-emacs@gnu.org>
2008-10-21 11:26 ` Andreas Politz [this message]
2008-10-21 21:21 ` save-current-buffer Nikolaj Schumacher
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=1224588747.694138@arno.fh-trier.de \
--to=politza@fh-trier.de \
--cc=help-gnu-emacs@gnu.org \
/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.