Subject: bug#12766: read-from-minibuffer does not preserve current-buffer

From: Stefan Monnier <[email-masked]>
Date: Tue, 30 Oct 2012 09:51:18 -0400

>> % src/emacs -Q --eval "(setq initial-frame-alist '((minibuffer . nil)))"
>> M-: (with-temp-buffer (list (read-string "toto: ") (current-buffer))) RET
> Two changes I made could be involved:
> (1) `select-window' now always makes the window's buffer current.
> (2) read_minibuf now calls set_window_buffer instead of
>     Fset_window_buffer.

I think (1) is more likely to be the problem.  Could you check
read_minibuf to see which unwind is supposed to reset the
current buffer?
Maybe that code worked by accident (.e.g relying on the fact that
select-window didn't set current-buffer in that corner case) and the
right fix is simply to explicitly save&restore current buffer.

> Also, is this related to the comment
>        ;; FIXME: kill-buffer can change current-buffer in some odd cases.
> in `with-temp-buffer'?

No, (current-buffer) is evaluated before the buffer gets killed, and the
bug shows up with with-temp-buffer (the recipe is just shorter with
with-temp-buffer, but you can try it with (with-current-buffer
(get-buffer-create " *sm-test*") ...) to convince yourself).

        Stefan