[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: with-current-buffer (was: fit-window-to-buffer)
From: |
Miles Bader |
Subject: |
Re: with-current-buffer (was: fit-window-to-buffer) |
Date: |
Mon, 27 Jun 2005 15:28:54 +0900 |
On 6/27/05, Juri Linkov <address@hidden> wrote:
> (with-current-buffer "c"
> (pop-to-buffer "b"))
> (message "%s" (buffer-name (current-buffer))))
>
> At the end, it print "a" as the current buffer name, but actually
> this command makes the buffer "b" current. Shouldn't it print "b"?
I think this isn't a bug -- the `with-current-buffer' form of course
restores the current buffer to be "a" after the wrapped code is
finished; why would you expect differently?
As I understand it, what `pop-to-buffer' does is set the window-buffer
of the selected window, in _addition_ to setting the current buffer,
and the main emacs interaction loop always restores the current buffer
to be the window-buffer of the selected window when you look for the
next command.
So in your example, `pop-to-buffer' sets the current buffer and the
window-buffer-of-selected-widnow to be "b", then the
`with-current-buffer' form (correctly) restores the current buffer to
be "a" again, then you print your message [which says "current buffer
is a"], then the interaction loop goes to read a command, which sets
the current buffer based on the window state -- which is "b", because
of pop-to-buffer's effect.
-Miles
--
Do not taunt Happy Fun Ball.
Re: with-current-buffer (was: fit-window-to-buffer), Richard M. Stallman, 2005/06/27