Subject: Re: bug#66187: read-file-name unexpected behavior when MUSTMATCH is a function

From: Stefan Monnier <[email-masked]>
Date: Thu, 05 Oct 2023 15:34:32 -0400

>> For example, given:
>> 
>> (completing-read "Prompt: " '("a" "b") nil
>>                  (lambda (input)
>>                    (string= "a" input)))
>> 
>> I expected that the prompt would refuse to complete "b". I was wrong.
>> 
>> Since completing-read is such a fundamental part of Emacs, I doubt it
>> will be possible to change this behavior.  What do you think about the
>> attached patch to clarify the completing-read docstring?

The use of a function as `require-match` is brand new in Emacs-29, so
I think it's not too late to fix it.  I think rather than fixing the doc
we should fix the behavior, e.g. with the patch below.

        Stefan

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 2120e31775e..d4da2d0d19b 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1835,15 +1835,13 @@ completion--complete-and-exit
   (cond
    ;; Allow user to specify null string
    ((= beg end) (funcall exit-function))
-   ;; The CONFIRM argument is a predicate.
-   ((and (functionp minibuffer-completion-confirm)
-         (funcall minibuffer-completion-confirm
-                  (buffer-substring beg end)))
-    (funcall exit-function))
    ;; See if we have a completion from the table.
-   ((test-completion (buffer-substring beg end)
-                     minibuffer-completion-table
-                     minibuffer-completion-predicate)
+   ((if (functionp minibuffer-completion-confirm)
+        (funcall minibuffer-completion-confirm
+                 (buffer-substring beg end))
+      (test-completion (buffer-substring beg end)
+                       minibuffer-completion-table
+                       minibuffer-completion-predicate))
     ;; FIXME: completion-ignore-case has various slightly
     ;; incompatible meanings.  E.g. it can reflect whether the user
     ;; wants completion to pay attention to case, or whether the