Subject: bug#74616: 30.0.92; tmm always displays the *Completions* buffer

From: Daniel Mendler <[email-masked]>
Date: Sun, 15 Dec 2024 11:02:29 +0100

Juri Linkov <[email-masked]> writes:

>> Thanks for finding this. The problem was that `initial-input' was passed
>> directly to `completion-metadata'. I replaced `initial-input' with `(or
>> initial-input "")'. See the updated patch attached to this mail.
>
> It seems this change caused another regression: 'ffap' on a file name
> fails with the error:

Oh, I see. The INITIAL-INPUT argument can be a cons pair too.  See the
patch attached to this mail which fixes the problem.

Daniel

>From 234fbf9b2e05c73b6197f4db9e88c694e54a95a2 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <[email-masked]>
Date: Sun, 15 Dec 2024 10:57:59 +0100
Subject: [PATCH] completion-eager-display: Handle INITIAL-INPUT cons

The INITIAL-ARGUMENT passed to `completing-read' can either be
nil, or a string or a pair (STRING . POSITION).  Handle each of
these three cases.

* lisp/minibuffer.el (completing-read-default): Handle cons pair
INITIAL-ARGUMENT.
---
 lisp/minibuffer.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index dfc62c25f38..9a8545c56a6 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4857,8 +4857,12 @@ completing-read-default
                 ;; `completion-eager-display' is t or if eager display
                 ;; has been requested by the completion table.
                 (when completion-eager-display
-                  (let* ((md (completion-metadata (or initial-input "")
-                                                  collection predicate))
+                  (let* ((md (completion-metadata
+                              (pcase initial-input
+                                (`(,str . ,pos) (substring str 0 pos))
+                                ((pred stringp) initial-input)
+                                (_ ""))
+                              collection predicate))
                          (fun (completion-metadata-get md 'eager-display)))
                     (when (or fun (eq completion-eager-display t))
                       (funcall (if (functionp fun)
-- 
2.45.2