Subject: 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: Wed, 04 Aug 2021 11:39:04 +0300

>> +  ;; When read_minibuf doesn't restore all previous windows,
>> +  ;; then at least pop down the completions window.
>> +  (unless read-minibuffer-restore-windows
>> +    (minibuffer-hide-completions))
>
> Hm...  Well, I guess that's what most people would want...  but...

The new option read-minibuffer-restore-windows is quite unusable
without the above change: selecting a completion from the
completions buffer will leave the completions buffer on the screen.

> should it be user-controllable?  Perhaps read_minibuffer_restore_windows
> shouldn't be a boolean, but allow values like t, 'completions and nil,
> where 'completions would trigger this behaviour?

Then I propose a new hook, e.g. read-minibuffer-restore-functions
with the default value '(minibuffer-hide-completions).  Then such hook
could be run instead of restoring the window configuration, i.e.
the logic could be:

  if (read_minibuffer_restore_windows)
    record_unwind_protect (restore_window_configuration,
			   list3 (Fcurrent_window_configuration (Qnil),
				  Qt, Qt));
  else
    safe_run_hooks (Qread_minibuffer_restore_functions);