Subject: Re: bug#63967: 28.2; switch-to-buffer in normal window fails if minibuffer window is active

From: Alan Mackenzie <[email-masked]>
Date: Sat, 17 Jun 2023 11:31:54 +0000

Hello, Eli.

On Wed, Jun 14, 2023 at 15:15:14 +0300, Eli Zaretskii wrote:
> > Date: Tue, 13 Jun 2023 21:36:37 +0000
> > Cc: [email-masked], [email-masked], [email-masked],
> >   [email-masked], [email-masked]
> > From: Alan Mackenzie <[email-masked]>
> > 
> > So I see the fix somewhat along the lines of removing the offending
> > Fset_frame_selected_window from minibuffer_unwind, and maybe rearranging
> > the calls to record_unwind_protect* in read_minibuf to arrange for the
> > window configuration call to do the job of restoring the "current"
> > window.
> > 
> > It seems to me you might want to put the fix into Emacs 29.  Am I right?

> Yes.  I wouldn't be pinging you if it weren't so.

> So I hope you will present a suggested patch soon, and that it will be
> simple and safe enough to install on the release branch.  TIA.

After spending quite some time looking at why that call to
Fset_frame_selected_window went in in the first place, and checking
quite a few of the bug scenarios from 2021, I'm now convinced that the
sole fix we need is to remove that call from minibuffer_unwind.

It's certainly a simple patch, and I think it's safe enough for Emacs
29.  Maybe other people (e.g. Martin) would be good enough to give it a
quick going over before we commit it.

diff --git a/src/minibuf.c b/src/minibuf.c
index d5f95968ae1..bcb7eb9375d 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1266,9 +1266,6 @@ minibuffer_unwind (void)
 	  set_window_buffer (window, Fcar (entry), 0, 0);
 	  Fset_window_start (window, Fcar (Fcdr (entry)), Qnil);
 	  Fset_window_point (window, Fcar (Fcdr (Fcdr (entry))));
-	  /* set-window-configuration may/will have unselected the
-	     mini-window as the selected window.  Restore it. */
-	  Fset_frame_selected_window (exp_MB_frame, window, Qnil);
 	}
       else
 	set_window_buffer (window, nth_minibuffer (0), 0, 0);

-- 
Alan Mackenzie (Nuremberg, Germany).