Subject: bug#745: pop-to-buffer, frames, and input focus

From: martin rudalics <[email-masked]>
Date: Wed, 20 Aug 2008 16:50:50 +0200

>   (let ((frame (selected-frame))
 >         (pop-up-frames t))
 >     (display-buffer (get-buffer-create "foo"))
 >     (select-frame-set-input-focus frame))
 >
 >   (let ((display-buffer-reuse-frames t))
 >     (pop-to-buffer "foo"))
 >
 >   shell$ emacs -Q -l pop-to-buffer-test.el
 >
 > Pops up two frames, one frame displays the "foo" buffer and the other
 > the "*scratch*" buffer (so far so good).  But the "foo" frame has not
 > the input focus.  Isn't pop-to-buffer supposed to switch input focus
 > too?

      (select-frame-set-input-focus frame))

gives input focus to the previously selected frame.

 > Also note that I had to save and restore the selected frame
 > around display-buffer.  If I try
 >
 >   emacs -Q --eval '(let ((pop-up-frames t))
 >                      (display-buffer (get-buffer-create "foo")))'
 >
 > the "foo" buffer is selected, even though display-buffer should not
 > switch the selected window.

I'm not sure whether on some system there were problems when raising a
frame and/or giving it input focus, and not selecting it.  At least with
Emacs 22 the frame was selected already.  Since there's only one window
on the new frame, that window must be selected as well.

In any case you're right: either the window must not be selected or the
documentation should tell when and why it selects the window.

 > Not even save-window-excursion stops display-buffer from switching the
 > frame:
 >
 >   emacs -Q --eval '(save-window-excursion
 >                      (let ((pop-up-frames t))
 >                         (display-buffer (get-buffer-create "foo"))))'

`save-window-excursion' is of no use here: It permits you to change the
contents of a frame in the body and restore the initial contents
afterwards.  You do that with the originally selected frame here.  The
new frame created by `display-buffer' is not affected by this.

martin