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

From: Alan Mackenzie <[email-masked]>
Date: Tue, 13 Jun 2023 21:36:37 +0000

Hello, Eli.

On Tue, Jun 13, 2023 at 21:43:13 +0300, Eli Zaretskii wrote:
> > Cc: [email-masked], [email-masked], [email-masked],
> >  [email-masked]
> > Date: Sun, 11 Jun 2023 16:53:48 +0300
> > From: Eli Zaretskii <[email-masked]>
> > 
> > > Do you want me to fix this bug?  It seems there are quite a lot of people
> > > who've made observations about it in the last couple of days.
> > 
> > I want to fix the bug whose recipe is in
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63967#5 and other
> > similar ones, yes.  Basically, if Emacs reads from a recursive
> > minibuffer when the selected window before that was not a mini-window,
> > we now signal a user-error, which is a regression since Emacs 28, and
> > I'd like that to be solved.  But please begin by looking at the
> > solution proposed by Martin in
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63967#38 and tell if it
> > looks good to you, and if not, why not.

> Ping!  Any progress there?

Sorry.  I've had a few very busy days in real life.

Firstly, I'm reasonably sure that the Fset_frame_selected_window I put
into minibuf_unwind was a mistake based on the misconception that after
reading the minibuffer recursively, we always wanted to go back to the
next outer minibuffer.

I think Martin's patch (from 2023-06-10 08:52 +0200) is along the right
lines, i.e. go back to the invoking window rather than the minibuffer
window.  But I'm not sure whether it might be better, from the point of
view of preserving maintainability of read_minibuf, to try to get the
restore_window_buffer_configuration call to go back to the calling
window, rather than adding the extra parameter to minibuffer_unwind.

It would be somewhat complicated by the need to go to some other window
if that calling window no longer exists.  We need to decide which
window.  This dilemma might have been what moved me to put that
Fset_frame_selected_window in in the first place.  :-(

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?

-- 
Alan Mackenzie (Nuremberg, Germany).