[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#67210: 30.0.50; completing-read with REQUIRE-MATCH=t can sometimes r
From: |
Spencer Baugh |
Subject: |
bug#67210: 30.0.50; completing-read with REQUIRE-MATCH=t can sometimes return a non-match |
Date: |
Thu, 16 Nov 2023 11:36:57 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Or perhaps completion-emacs22-try-completion is violating the spec of
>>> completion-try-completion, and should be returning nil in this case?
>
> The "emacs22" style disregards the text after point to compute the
> completions, so "foo" would be a valid return value as well, but indeed
> t seems wrong because that should apply to the complete input.
I think "foo" (or more specifically '("foo" . 3)) might be a bit
unexpected, because then if you pressed TAB with the input foo|bar, the
bar would be deleted. And emacs22 completion usually doesn't delete the
text after point, it just ignores it.
So '("foobar" . 3) seems better. Open to counterarguments of course.
A patch which implements this is below.
>From e96e154f1ab6c0a743b88cfd7a9b59e14726b07a Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Thu, 16 Nov 2023 11:34:08 -0500
Subject: [PATCH] Return t from completion-emacs22-try-completion only for
completions
The emacs22 completion style ignores the text after point when
computing completions. However, it still needs to take into account
the entire string it's given, to avoid returning incorrect values.
Previously, completion-emacs22-try-completion would return t if the
text before point was an exact completion. But this is effectively
saying that the entire input string was an exact completion, which may
not be correct. This would cause completing-read with REQUIRE-MATCH=t
to return a non-completion.
Now, completion-emacs22-try-completion only returns t if the entire
input string is an exact completion.
* lisp/minibuffer.el (completion-emacs22-try-completion): Return t
only if the entire input string is an exact completion. (Bug#67210)
---
lisp/minibuffer.el | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 07a284134d6..e9a349d39ea 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3526,8 +3526,15 @@ completion-emacs21-all-completions
(defun completion-emacs22-try-completion (string table pred point)
(let ((suffix (substring string point))
(completion (try-completion (substring string 0 point) table pred)))
- (if (not (stringp completion))
- completion
+ (cond
+ ((eq completion t)
+ ;; The prefix is an exact and unique completion, but STRING
+ ;; might not be a completion.
+ (if (test-completion string table)
+ t
+ (cons string point)))
+ ((not (stringp completion)) completion)
+ (t
;; Merge a trailing / in completion with a / after point.
;; We used to only do it for word completion, but it seems to make
;; sense for all completions.
@@ -3541,7 +3548,7 @@ completion-emacs22-try-completion
(eq ?/ (aref suffix 0)))
;; This leaves point after the / .
(setq suffix (substring suffix 1)))
- (cons (concat completion suffix) (length completion)))))
+ (cons (concat completion suffix) (length completion))))))
(defun completion-emacs22-all-completions (string table pred point)
(let ((beforepoint (substring string 0 point)))
--
2.39.3