Subject: Re: bug#61286: 28.2; No visible candidates after toggle icomplete-vertical-mode

From: Eli Zaretskii <[email-masked]>
Date: Sun, 05 Feb 2023 08:44:33 +0200

tags 61286 notabug
thanks

> From: Fernando de Morais <[email-masked]>
> Date: Sat, 04 Feb 2023 22:51:50 -0300
> 
> To reproduce, which is possible with 'emacs -Q', please:
> 
> 1. Evaluate the following snippet:
> 
>   (progn
>     (with-eval-after-load 'icomplete
>       (define-key icomplete-minibuffer-map (kbd "C-v") #'icomplete-vertical-mode)
>       (customize-set-variable 'icomplete-show-matches-on-no-input t))
>     (icomplete-mode))
> 
> 2. C-x C-f
> 3. C-v (to toggle `icomplete-vertical-mode' while still in the minibuffer).
> 
> Results in:
> 
>   - Only the first candidate can be seen in the vertical list.
> 
> Completion works as expected.  Quitting and starting a new command, with
> `icomplete-vertical-mode' still enabled, displays the completion
> candidates correctly.

That's because icomplete-vertical-mode adds its own function to
icomplete-minibuffer-setup-hook, but when you invoke C-v in the
minibuffer, that's too late: you already entered the minibuffer, so
the minibuffer is not set up as icomplete-vertical-mode expects.

To solve this, bind C-v to a command that does what
icomplete--vertical-minibuffer-setup does, in addition to turning on
icomplete-vertical-mode, and then it will work as you expect.  Like
this:

  (defun icvsetup ()
    (interactive)
    (setq-local icomplete-hide-common-prefix nil
		icomplete-prospects-height 25
		redisplay-adhoc-scroll-in-resize-mini-windows nil)
    (icomplete-vertical-mode))

  (progn
      (with-eval-after-load 'icomplete
	(define-key icomplete-minibuffer-map (kbd "C-v") #'icvsetup)
	(customize-set-variable 'icomplete-show-matches-on-no-input t))
      (icomplete-mode))

IOW, this is a cockpit error, not a bug in Emacs.