Subject: Re: bug#60411: 29.0.60; minibuffer-next-completion skips first candidate when completions-header-format and completion-show-help are nil

From: Gregory Heytings <[email-masked]>
Date: Sat, 31 Dec 2022 15:02:57 +0000

>
> For completeness, you may consider also handling the case where 
> completions-header-format is an empty string, which is another not too 
> unreasonable way to disable the header. minibuffer-next-completion still 
> skips the first candidate for that case.
>

Thanks for your feedback!  Indeed, that's another bug, which makes a fix 
elsewhere in the code even less likely.  It is fixed in the attached 
patch.  Can you try it?

Eli, do you have objections to that patch?
From d0443e0215196b1576800ae1d5f0f5357a8a8dad Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Sat, 31 Dec 2022 14:50:13 +0000
Subject: [PATCH] Fix handling of completions-header-format

* lisp/minibuffer.el (display-completion-list): Insert an
invisible line when completions-header-format is not a string (in
particular, nil) or is an empty string.  Fixes bug#60411.
Also, do not use completions-header-format when it is not a
string.
---
 lisp/minibuffer.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 7a720cf2c0..6c7413c555 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2275,8 +2275,14 @@ display-completion-list
 
     (with-current-buffer standard-output
       (goto-char (point-max))
-      (when completions-header-format
+      (when (stringp completions-header-format)
         (insert (format completions-header-format (length completions))))
+      (when (or (not (stringp completions-header-format))
+                (string= completions-header-format ""))
+        ;; Insert an invisible line, otherwise the first call to
+        ;; 'minibuffer-next-completion' might select the second
+        ;; completion candidate.  See bug#60411.
+        (insert (propertize "\n" 'invisible t)))
       (completion--insert-strings completions group-fun)))
 
   (run-hooks 'completion-setup-hook)
-- 
2.39.0