=== modified file 'src/frame.c' --- src/frame.c 2013-08-15 16:28:42 +0000 +++ src/frame.c 2013-08-25 17:22:14 +0000 @@ -1110,6 +1110,44 @@ return 0; } +/* Set minibuf_window preferably to the selected frame's minibuffer + window. If the selected frame doesn't have one, get some other + frame's minibuffer window. not-this is a frame that must be + skipped. select non-zero means select the new window. */ +Lisp_Object +set_minibuf_window (Lisp_Object not_this, int select) +{ + Lisp_Object frames, this, window; + + if (FRAME_HAS_MINIBUF_P (XFRAME (selected_frame))) + window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame)); + else + FOR_EACH_FRAME (frames, this) + { + if (!EQ (this, not_this) && FRAME_HAS_MINIBUF_P (XFRAME (this))) + { + window = FRAME_MINIBUF_WINDOW (XFRAME (this)); + break; + } + } + + if (!WINDOWP (window)) + emacs_abort (); + else + { + /* Use set_window_buffer instead of Fset_window_buffer (see + discussion of bug#11984, bug#12025, bug#12026). */ + set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0); + minibuf_window = window; + + /* If the previous minibuffer window was selected, select the new + one. */ + if (select) + Fselect_window (minibuf_window, Qnil); + } +} + + /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME unconditionally. x_connection_closed and delete_terminal use this. Any other value of FORCE implements the semantics @@ -1245,18 +1283,7 @@ /* Don't allow minibuf_window to remain on a deleted frame. */ if (EQ (f->minibuffer_window, minibuf_window)) - { - /* Use set_window_buffer instead of Fset_window_buffer (see - discussion of bug#11984, bug#12025, bug#12026). */ - set_window_buffer (sf->minibuffer_window, - XWINDOW (minibuf_window)->contents, 0, 0); - minibuf_window = sf->minibuffer_window; - - /* If the dying minibuffer window was selected, - select the new one. */ - if (minibuffer_selected) - Fselect_window (minibuf_window, Qnil); - } + set_minibuf_window (frame, minibuffer_selected); /* Don't let echo_area_window to remain on a deleted frame. */ if (EQ (f->minibuffer_window, echo_area_window)) @@ -1683,16 +1710,9 @@ if (NILP (force) && !other_visible_frames (f)) error ("Attempt to make invisible the sole visible or iconified frame"); - /* Don't allow minibuf_window to remain on a deleted frame. */ + /* Don't allow minibuf_window to remain on an invisible frame. */ if (EQ (f->minibuffer_window, minibuf_window)) - { - struct frame *sf = XFRAME (selected_frame); - /* Use set_window_buffer instead of Fset_window_buffer (see - discussion of bug#11984, bug#12025, bug#12026). */ - set_window_buffer (sf->minibuffer_window, - XWINDOW (minibuf_window)->contents, 0, 0); - minibuf_window = sf->minibuffer_window; - } + set_minibuf_window (frame, 0); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM @@ -1716,14 +1736,7 @@ /* Don't allow minibuf_window to remain on an iconified frame. */ if (EQ (f->minibuffer_window, minibuf_window)) - { - struct frame *sf = XFRAME (selected_frame); - /* Use set_window_buffer instead of Fset_window_buffer (see - discussion of bug#11984, bug#12025, bug#12026). */ - set_window_buffer (sf->minibuffer_window, - XWINDOW (minibuf_window)->contents, 0, 0); - minibuf_window = sf->minibuffer_window; - } + set_minibuf_window (frame, 0); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM