Subject: Re: bug#45072: 28.0.50; Emacs switches other buffer back uncontrollably, if other window's buffer is changed by user during minibuffer editing

From: Juri Linkov <[email-masked]>
Date: Thu, 10 Dec 2020 10:32:54 +0200

> We'd have to augment the 'quit-restore' mechanism somehow and run it on
> all windows instead of restoring the configuration.
>
> But I still don't understand the logic of the following:
>
> (1) Start minibuffer interaction, type a-
>
> (2) Pop up a completion window for a- and accept suggestion a-b

What do you type to accept a suggestion?  I can't find a key
to accept a suggestion without exiting the minibuffer.

> (3) Type another - so you now get a-b-
>
> (4) Pop up a completion window for a-b- and accept a-b-c
>
> In this scenario I'd want, after accepting a-b, the completion window to
> disappear (or show its old buffer again) without the minibuffer action
> having terminated.  So I'm still convinced that restoring a previous
> state should be triggered by the completion mechanism and not by the
> read from minibuffer mechanism.

Then maybe the commands that pop up the completions window
should clean up their windows after use.  What would be the
right place to remove used windows?  Maybe in exit-minibuffer?
Or in some unwind-protect in case the user types C-g?

> One thing that has to be considered too is user interaction during
> completion: Suppose I have one window, the completion mechanism pops up
> a new one and I delete the old one.  Terminating completion now cannot
> delete the new window (especially if it's on the only frame in use) but
> has to show another buffer in the new window.  It maybe should try to
> show the one previously shown in the old window.

This means that quit-window should be used on the completions window.
It should do the right thing: either restore a previous buffer in that window,
or close the window if no more buffers were displayed in it.

> And let's not forget that the completion mechanism might pop up a new
> frame or a window on any other frame.  In such case, restoring window
> configurations won't help at all.

That's fine, I create a new tab when the minibuffer is active,
to preserve new windows created during the active minibuffer.
For more convenience, now I installed a patch that allows creating
a new tab even from the minibuffer.