Subject: Re: bug#59486: completion-auto-wrap disobeyed by vertical navigation

From: Juri Linkov <[email-masked]>
Date: Sun, 05 Nov 2023 19:53:23 +0200

>> The argument zero to get-buffer-window AFAIU means that it will return
>> non-nil when the buffer is shown in some window on an iconified frame,
>> and I wonder why we would consider such a buffer "visible".
>
> (get-buffer-window "*Completions*" 0) is used everywhere in minibuffer.el
> and simple.el, so the argument zero is for compatibility with other
> minibuffer completion commands.

During testing I discovered that the condition should be more complex.
The problem is that the logic should be bound only to the minibuffer
that showed the completions, not in other minibuffers within a set of
recursive minibuffers.  An example: `M-x TAB C-h v down RET'
raised an error "Minibuffer is not active for completion".
This error comes from `choose-completion-string',
so I copied the same logic from `choose-completion-string':

  (when-let ((window (get-buffer-window "*Completions*" 0)))
    (when (eq (buffer-local-value 'completion-reference-buffer
                                  (window-buffer window))
              (window-buffer (active-minibuffer-window)))
      cmd))

>> Same here.
> Here is a new patch:

Now pushed the fixed patch.