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