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#65137: 29.1; completion-substring-try-completion doesn't return the longest common substring Date: Mon, 07 Aug 2023 20:41:12 -0400 Message-ID: References: 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="36801"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 65137@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 08 02:42:25 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 1qTAnn-0009M7-Rx for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Aug 2023 02:42:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTAnU-0005yF-3T; Mon, 07 Aug 2023 20:42:04 -0400 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 1qTAnS-0005xl-A0 for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 20:42:02 -0400 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 1qTAnS-0005aW-1h for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 20:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qTAnR-0007FV-Ks for bug-gnu-emacs@gnu.org; Mon, 07 Aug 2023 20:42:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Aug 2023 00:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65137 X-GNU-PR-Package: emacs Original-Received: via spool by 65137-submit@debbugs.gnu.org id=B65137.169145528427819 (code B ref 65137); Tue, 08 Aug 2023 00:42:01 +0000 Original-Received: (at 65137) by debbugs.gnu.org; 8 Aug 2023 00:41:24 +0000 Original-Received: from localhost ([127.0.0.1]:34567 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTAmp-0007Ed-Pq for submit@debbugs.gnu.org; Mon, 07 Aug 2023 20:41:24 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:35605) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTAmk-0007EL-Ds for 65137@debbugs.gnu.org; Mon, 07 Aug 2023 20:41:21 -0400 In-Reply-To: (Spencer Baugh's message of "Mon, 07 Aug 2023 19:50:00 -0400") 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:266907 Archived-At: --=-=-= Content-Type: text/plain Here's a patch fixing this. It's definitely just a bug in the implementation of completion-pcm--merge-completions - see my commit message for details. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Correctly-handle-common-prefixes-in-substring-comple.patch >From ea63217c1c85f1ca4f1f22b9c4781167de6cf00d Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Mon, 7 Aug 2023 20:20:34 -0400 Subject: [PATCH] Correctly handle common prefixes in substring completion substring completion is implemented by passing the `prefix' symbol as part of the pattern passed to completion-pcm--merge-completions. This symbol is supposed to "grow" the completion only as a suffix, not as a prefix. The old behavior of completion-pcm--merge-completions when processing a `prefix' element in the pattern was to find the common prefix of all the completions in that part of the pattern (using try-completion) and then completely discard that common prefix. Then the actual logic for `prefix' would run with completion--common-suffix. However, if all the completion candidates had a common prefix while processing a `prefix' element, then it would both discard the common prefix *and* skip the completion--common-suffix logic. If there was also a common suffix, e.g. with the following invocation: (completion-pcm--merge-completions '("axbc" "aybc") '(prefix "c")) then this would produce the wrong result by ignoring the common suffix "b". The new behavior is to simply not bother generating the common prefix for `prefix' elements, since we don't use it anyway, and just pretend it's always empty for `prefix' elements. Then the completion--common-suffix logic always runs. * lisp/minibuffer.el (completion-pcm--merge-completions): Don't ignore a common suffix in a `prefix' pattern element when there's also a common prefix. --- lisp/minibuffer.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index d2c7e66d2a0..1aa29318bd2 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4029,12 +4029,15 @@ completion-pcm--merge-completions ;; different capitalizations in different parts. ;; In practice, it doesn't seem to make any difference. (setq ccs (nreverse ccs)) - (let* ((prefix (try-completion fixed comps)) + (let* ((prefix + ;; We pretend as if there's no common prefix at all for + ;; `prefix', so we go to completion--common-suffix + (if (eq elem 'prefix) "" (try-completion fixed comps))) (unique (or (and (eq prefix t) (setq prefix fixed)) (and (stringp prefix) + (not (string-empty-p prefix)) (eq t (try-completion prefix comps)))))) - (unless (or (eq elem 'prefix) - (equal prefix "")) + (unless (equal prefix "") (push prefix res)) ;; If there's only one completion, `elem' is not useful ;; any more: it can only match the empty string. -- 2.39.3 --=-=-=--