Subject: bug#11939: 24.1; `save-buffers-kill-emacs' loses minibuffer focus whenit calls `list-processes'

From: martin rudalics <[email-masked]>
Date: Thu, 26 Jul 2012 18:05:45 +0200

>>  > So I tried instead redirecting the focus to the minibuffer
 >>  > frame.  That worked OK, but the default buffer for killing
 >>  > with C-x k was ` *Minibuf-0*', not *shell* or *Process List*.
 >>  >
 >>  > It seems that when a new frame is created, the default
 >>  > value for C-x k (and other buffer commands) becomes *Minibuf-0*.
 >>  > I can of course choose not to use the default value, but it
 >>  > would be good to get this part fixed also.
 >>
 >> You mean *Minibuf-0* became the current buffer?  Probably so
 >> because you selected its window.
 >
 > I did not do so explicitly, AFAIK.  But perhaps read-from-minibuffer (actually
 > the C code for it) does that?  I do not see anywhere that I do so in my code.

It indeed selects the window and sets the current buffer.  But C-x k
should never offer *Minibuf-0* for killing.  Does it really prompt with
*Minibuf-0*?  If so, then the following excerpt from Fcall_interactively

	case 'b':   		/* Name of existing buffer */
	  args[i] = Fcurrent_buffer ();
	  if (EQ (selected_window, minibuf_window))
	    args[i] = Fother_buffer (args[i], Qnil, Qnil);
	  args[i] = Fread_buffer (callint_message, args[i], Qt);
	  break;

is broken.  IIUC it means that the current buffer is the buffer of the
minibuffer window (how did that happen?) but the minibuffer window is
not selected.  What is missing from the form below to reproduce it?

(progn
   (add-hook 'after-make-frame-functions
	    #'(lambda (frame)
		(redirect-frame-focus
		 frame (window-frame (minibuffer-window)))))
   (setq pop-up-frame-function (lambda () (make-frame '((minibuffer . nil)))))
   (setq pop-up-frames t)
   (display-buffer "*Messages*")
   (yes-or-no-p "???"))

martin