Subject: RE: [External] : bug#26513: 25.2; pop-up-frames and *Completions* buffer

From: Drew Adams <[email-masked]>
Date: Thu, 17 Feb 2022 16:40:20 +0000

>>> >From emacs -Q:
>>>
>>> M-x set-variable RET pop-up-frames RET t RET
>>> M-x global- TAB
>>>
>>> The *Completions* buffer is opened in a new frame, but the cursor is in
>>> the frame too, so the user has to switch back to the minibuffer to
>>> continue typing.
>>
>> This problem is still present in Emacs 29.  I guess the general solution
>> here would be for completion to ensure that it's gotten focus back again
>> after displaying the *Completions* buffer?
> 
> Maybe Stefan Monnier can tell us what he does in such case.
> 
> I can offer the attached, largely untested patch.  A possible
> customization would then be
> 
> (customize-set-variable
>   'display-buffer-alist
>   '(("*Completions*"
>      (display-buffer-reuse-window
>       display-buffer-pop-up-frame)
>      (reusable-frames . t)
>      (redirect-frame-focus . t))))

22 years ago I reported this problem.
I fixed it for my use in this way...
 
tl;dr:

Use a standalone minibuffer frame, and a
separate frame for `*Completions*' that's
displayed with a function that does this:

(redirect-frame-focus (selected-frame)
                      1on1-minibuffer-frame)
___

In my code I do this by adding function
`1on1-display-*Completions*-frame' to
`special-display-buffer-names'.  What it does:

1. `redirect-frame-focus' to the standalone
minibuffer frame if the minibuffer is active, or
to `completion-reference-buffer' (unless it's
`*Completions*') otherwise.

2. Return the window resulting from calling the
value of `special-display-function' at the start
of `1on1-display-*Completions*-frame'.
___

It does other stuff as well, which is why it
needs, at the outset, to get the window to
return:
It optionally uses the same font family for
`*Completions*' as the frame selected when the
minibuffer was set up.  It optionally shrinks
the text in `*Completions*' by a user-defined
amount.  It optionally repositions frame
`*Completions*' to the right edge of the
display temporarily, to make both it and the
original frame more visible.
___

(`display-buffer-alist' could presumably be
used instead of special-display.  I don't use
it because special-display is simpler and it's
available also for older Emacs releases that
don't have `display-buffer-alist'.)
___

The code I use is in `oneonone.el':

https://www.emacswiki.org/emacs/download/oneonone.el