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

From: "Drew Adams" <[email-masked]>
Date: Wed, 25 Jul 2012 10:28:21 -0700

Martin, I tried what you suggested about `after-make-frame-functions' again, but
this time with my setup (with unmodified oneonone.el).  I added only this to my
usual setup:

(add-hook 'after-make-frame-functions
          (lambda (frame)
            (redirect-frame-focus frame frame)))

I then ran through the scenario that lead to a crash (C-x C-c, no to exit, C-x k
*shell* + yes, C-x k again, try to type or move cursor).

No crash in this case, but when I try to type something or move the cursor after
the second C-x k (which is the point at which the crash occurred), I can see
that the input is being sent to buffer & frame *Process List*.  That's not what
you expected, is it?  It is not TRT, in any case.

I do not understand, BTW, why you redirect the focus from the new frame to
itself, instead of to the minibuffer frame.

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.

Or as a workaround I can explicitly select the frame of the buffer I want to
kill - e.g., click the title bar of frame *shell*.  After I do that, that buffer
becomes the default value for C-x k.

IOW, it seems that not only is the input focus redirected to the minibuffer
frame, but also the current buffer is changed to *Minibuf-0*.  And if I do `M-:
(current-buffer)' I do get *Minibuf-0*.  Is it normal for frame-focus
redirection to change the current buffer also?  That does not seem right to me.

Anyway, aside from this problem of default value for C-x k, things seemed to
work OK.  So overall this seems like a reasonable solution, except for the
default buffer problem.  This is all I did, along with my usual setup:

(add-hook 'after-make-frame-functions
          (lambda (frame)
            (redirect-frame-focus frame (window-frame (minibuffer-window)))))