all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, 67210@debbugs.gnu.org
Subject: bug#67210: 30.0.50; completing-read with REQUIRE-MATCH=t can sometimes return a non-match
Date: Fri, 17 Nov 2023 12:18:23 -0500	[thread overview]
Message-ID: <ierleawi9i8.fsf@janestreet.com> (raw)
In-Reply-To: <jwv8r6w1i6k.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 17 Nov 2023 11:06:09 -0500")

[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>  (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)))
>
> I think we should test (equal "" suffix) instead.
> The cases where (equal "" suffix) is false but (test-completion string table)
> are sufficiently weird that returning t seems risky and I can't think of
> any reason why it's worthwhile to take this risk.

True.  I was thinking about the case where STRING is a completion, so it
would be nice to just return t.  But that would be caught by other
completion styles before emacs22 anyway.

Fixed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Return-t-from-completion-emacs22-try-completion-only.patch --]
[-- Type: text/x-patch, Size: 2318 bytes --]

From b196a456430ff6ddc4705bc012a14f615b360e37 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 | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 07a284134d6..5bba202603a 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3526,8 +3526,13 @@ 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)
+      (if (equal "" suffix)
+          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 +3546,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


  reply	other threads:[~2023-11-17 17:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 20:25 bug#67210: 30.0.50; completing-read with REQUIRE-MATCH=t can sometimes return a non-match Spencer Baugh
2023-11-16  1:29 ` Drew Adams
2023-11-16 14:47   ` Spencer Baugh
2023-11-16 17:13     ` Drew Adams
2023-11-16  5:38 ` Eli Zaretskii
2023-11-16 15:04   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 16:36     ` Spencer Baugh
2023-11-16 18:24       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 16:06       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 17:18         ` Spencer Baugh [this message]
2023-11-17 17:35           ` Stefan Monnier 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ierleawi9i8.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=67210@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.