From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <8334x6qmu7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1087"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 67210@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 17 18:19:31 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r42V8-000AZ4-DG for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Nov 2023 18:19:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r42Us-0000lv-Et; Fri, 17 Nov 2023 12:19:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r42Uh-0000hj-5s for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 12:19:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r42Ug-0001PE-1y for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 12:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r42Ug-0006lb-Av for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 12:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Nov 2023 17:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67210 X-GNU-PR-Package: emacs Original-Received: via spool by 67210-submit@debbugs.gnu.org id=B67210.170024151225974 (code B ref 67210); Fri, 17 Nov 2023 17:19:02 +0000 Original-Received: (at 67210) by debbugs.gnu.org; 17 Nov 2023 17:18:32 +0000 Original-Received: from localhost ([127.0.0.1]:47072 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r42UB-0006ks-Ir for submit@debbugs.gnu.org; Fri, 17 Nov 2023 12:18:31 -0500 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:42207) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r42U9-0006kf-Bj for 67210@debbugs.gnu.org; Fri, 17 Nov 2023 12:18:30 -0500 In-Reply-To: (Stefan Monnier's message of "Fri, 17 Nov 2023 11:06:09 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274508 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Return-t-from-completion-emacs22-try-completion-only.patch >From b196a456430ff6ddc4705bc012a14f615b360e37 Mon Sep 17 00:00:00 2001 From: Spencer Baugh 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 --=-=-=--