From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: michael_heerdegen@web.de, Eli Zaretskii <eliz@gnu.org>,
philipk@posteo.net, 66187@debbugs.gnu.org
Subject: bug#66187: read-file-name unexpected behavior when MUSTMATCH is a function
Date: Mon, 18 Dec 2023 21:52:33 -0500 [thread overview]
Message-ID: <87il4uvoob.fsf@breatheoutbreathe.in> (raw)
In-Reply-To: <jwvle9scrcm.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1733 bytes --]
Hello!
For reference, here's the little snippet I'm testing with:
(completing-read "Prompt: " '("a" "b") nil
(lambda (input)
(string= "a" input)))
where the only expected valid input is "a".
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Here's another potential solution. While the attached patch seems to
>> work, I'm not sure that minibuffer-completion-confirm should be checked
>> in completion--do-completion instead of completion--complete-and-exit.
>
> It's definitely better to check it in `completion--complete-and-exit`
> (which is about exiting and thus related to whether the content is
> acceptable) than in `completion--do-completion` (which is just about
> completion).
I'm still not sure `completion--complete-and-exit' is the best place to
check that input is valid before exiting.
`completion--do-completion' contains the following cond clause, which
prevents the user from exiting with, e.g., "c".
((null comp)
(minibuffer-hide-completions)
(unless completion-fail-discreetly
(ding)
(completion--message "No match"))
(minibuffer--bitset nil nil nil))
Perhaps we should also run that same body when REQUIRE-MATCH is a
function which returns nil?
> The patch looks OK, thanks. We could make it call `completion-function`
> instead of saying "no match" (after all, it has "complete" in its name),
> but it comes with its own set of problems.
If I understand correctly, the attached patch does this.
I think this works inside of `completion-complete-and-exit', but maybe
not inside of `minibuffer-force-complete-and-exit' since the former
calls `completion--do-completion' internally but the latter does not.
Still exploring ideas... Thanks!
Joseph
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-completing-read-functional-REQUIRE-MATCH-behavio-2.patch --]
[-- Type: text/x-diff, Size: 1803 bytes --]
From 7b779782504a7b94f64f100a1f8bb71c483873e5 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Mon, 18 Dec 2023 22:41:24 -0500
Subject: [PATCH] Fix completing-read functional REQUIRE-MATCH behavior
* lisp/minibuffer.el (completion--do-completion): Refuse to exit
minibuffer when REQUIRE-MATCH is a function which returns nil.
(completion--complete-and-exit): Delegate handling of functional
REQUIRE-MATCH to completion-function.
See bug#66187.
---
lisp/minibuffer.el | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 5c12d9fc914..5d26ff2423e 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1408,7 +1408,11 @@ when the buffer's text is already an exact match."
(- (point) beg)
md)))
(cond
- ((null comp)
+ ((or (null comp)
+ (and (eq t comp)
+ (functionp minibuffer-completion-confirm)
+ (not (funcall minibuffer-completion-confirm
+ (buffer-substring beg end)))))
(minibuffer-hide-completions)
(unless completion-fail-discreetly
(ding)
@@ -1849,10 +1853,8 @@ appear to be a match."
;; 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))
+ ((functionp minibuffer-completion-confirm)
+ (funcall completion-function))
;; See if we have a completion from the table.
((test-completion (buffer-substring beg end)
minibuffer-completion-table
--
2.41.0
next prev parent reply other threads:[~2023-12-19 2:52 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-24 21:31 bug#66187: read-file-name unexpected behavior when MUSTMATCH is a function Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-25 3:58 ` Michael Heerdegen
2023-09-25 5:12 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-25 21:33 ` Michael Heerdegen
2023-09-26 8:37 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-27 0:26 ` Michael Heerdegen
2023-09-27 0:55 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-27 1:43 ` Michael Heerdegen
2023-10-03 21:18 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-03 23:00 ` Drew Adams
2023-10-04 3:35 ` Michael Heerdegen
2023-10-04 5:22 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-05 1:12 ` Michael Heerdegen
2023-10-04 7:03 ` Eli Zaretskii
2023-10-05 19:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-05 20:20 ` Drew Adams
2023-10-06 4:47 ` Eli Zaretskii
2023-10-06 13:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-06 14:08 ` Drew Adams
2023-10-06 4:45 ` Eli Zaretskii
2023-10-06 13:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-06 13:46 ` Eli Zaretskii
2023-10-06 16:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-07 5:23 ` Eli Zaretskii
2023-10-07 14:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-07 15:09 ` Eli Zaretskii
2023-10-07 15:12 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 21:26 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-26 6:49 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-18 0:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-19 2:52 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-01-09 8:06 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25 20:53 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-28 19:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-28 19:28 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-06 5:55 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-29 12:00 ` Eli Zaretskii
2023-10-03 20:43 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-04 6:05 ` Eli Zaretskii
2023-10-04 6:25 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87il4uvoob.fsf@breatheoutbreathe.in \
--to=bug-gnu-emacs@gnu.org \
--cc=66187@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=joseph@breatheoutbreathe.in \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
--cc=philipk@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).