From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72819: [PATCH] Correctly include fixed strings before a prefix wildcard in PCM Date: Tue, 10 Sep 2024 12:31:13 -0400 Message-ID: References: <864j76jkny.fsf@gnu.org> Reply-To: Spencer Baugh 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="24983"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 72819@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 10 18:32:16 2024 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 1so3mp-0006MG-I2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 10 Sep 2024 18:32:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so3mY-0003Fw-NL; Tue, 10 Sep 2024 12:31:59 -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 1so3mX-0003BR-GZ for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 12:31:57 -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 1so3mX-0006CK-77 for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 12:31:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=RwA1pqL0KV0Dn64nuEteUJ3ehs3JCo2YSA678YQDx04=; b=vPpS8dsawUg+sE0heBt696YEs77Hr6X4qAw2bLm2jgAlBkEUYS7BE6Om/JWeb6GLofwLikRh8mjPUjmxwsmYZVdOqH5YZyVv9MVmnY/LAovN7JI1sX5lGFP6PPhEjkp90qhU+KzBBUu3E9T8OlxrHwlb8HCMZFMKlOAdXZa2mAWK9WgyqDDZ8sRqTPf+r73qe91GjZqhp8YR513S0bQ37udP7Q6tTmnOIhbAyFw6cyWYcPc9ITDwFjbNzFVMH2FhOhvJ8HJC9T3gKx8qu962gftxxdKZrcqlrr1D19O/FsyjHtwO2Z4pmGZ1KB3qkm3MWPVPz+NvWM74FneKtfSYVg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1so3mb-0005Vy-NA for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 12:32: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, 10 Sep 2024 16:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72819 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72819-submit@debbugs.gnu.org id=B72819.172598588721152 (code B ref 72819); Tue, 10 Sep 2024 16:32:01 +0000 Original-Received: (at 72819) by debbugs.gnu.org; 10 Sep 2024 16:31:27 +0000 Original-Received: from localhost ([127.0.0.1]:36897 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so3m2-0005V5-8a for submit@debbugs.gnu.org; Tue, 10 Sep 2024 12:31:26 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:47203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so3lz-0005Ul-JT for 72819@debbugs.gnu.org; Tue, 10 Sep 2024 12:31:24 -0400 In-Reply-To: <864j76jkny.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 27 Aug 2024 13:59:45 +0300") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1725985873; bh=RwA1pqL0KV0Dn64nuEteUJ3ehs3JCo2YSA678YQDx04=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=eK5Pc+2VPqlnu0tNym01FshAna/O84b7/uFIwm/w7Dp+QzSmMZKZApa6eQA1hAWmW Vu5SL+OVzqa0UB33X7H6JyieBPN9Qkf3TpXDxJzcKQ5KQ0NXIyLoJoSZMakLNAQSH9 rYbQ1SiWEiH7HWMLJ07MI6Va67q/PBmAuV95STwr/zbz2cnxRseIkjnJIn7+Zp1nQC tpD6otsEuJvuyMcFnJGEvs1c3t3ro6IVwt+doau7+jhNsRlkTKz3dibXp1M3OrzsEx uxRTd0zc1j6BCzK7Qxbz9NhwKUTN10F94wivbbYVGvWdiSbOSNaZaYApaprRNgDQpa wBdTU2aBQNxww== 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:291571 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Cc: monnier@iro.umontreal.ca >> From: Spencer Baugh >> Date: Mon, 26 Aug 2024 10:17:05 -0400 >> >> In 63a48252306a631dc07d62d19311433c7877bd27 I fixed a bug with > > Git tells me "bad object 63a48252306a631dc07d62d19311433c7877bd27", so > I couldn't figure out which commit are you referring to. Oops, here's the patch again with a corrected commit message: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Correctly-include-fixed-strings-before-a-prefix-wild.patch >From 1c9df731bacadd4ef762675af9903ccb0897a3ae Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Mon, 26 Aug 2024 10:12:51 -0400 Subject: [PATCH] Correctly include fixed strings before a prefix wildcard in PCM In 03ac16ece40ba3e3ba805d6a61cc457d84bf3792 I fixed a bug with the PCM implementation of substring completion, relating to the handling of PCM wildcards. However, this fix was incomplete. This change completes the fix by also including a fixed string if it appears before a `prefix' wildcard, even if try-completion doesn't discover that fixed string grows to a unique completion. I discovered this bug while working on enhancements to PCM completion related to completion-pcm-leading-wildcard. * lisp/minibuffer.el (completion-pcm--merge-completions): Include fixed strings before 'prefix wildcard. (bug#72819) * test/lisp/minibuffer-tests.el (completion-substring-test-5): Add a test for this behavior. --- lisp/minibuffer.el | 15 +++++++++------ test/lisp/minibuffer-tests.el | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6fae62b3904..1efe71f10e3 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4418,18 +4418,21 @@ completion-pcm--merge-completions (unique (or (and (eq prefix t) (setq prefix fixed)) (and (stringp prefix) (eq t (try-completion prefix comps)))))) - ;; if the common prefix is unique, it also is a common - ;; suffix, so we should add it for `prefix' elements - (unless (or (and (eq elem 'prefix) (not unique)) - (equal prefix "")) - (push prefix res)) ;; If there's only one completion, `elem' is not useful ;; any more: it can only match the empty string. ;; FIXME: in some cases, it may be necessary to turn an ;; `any' into a `star' because the surrounding context has ;; changed such that string->pattern wouldn't add an `any' ;; here any more. - (unless unique + (if unique + ;; if the common prefix is unique, it also is a common + ;; suffix, so we should add it for `prefix' elements + (push prefix res) + ;; `prefix' only wants to include the fixed part before the + ;; wildcard, not the result of growing that fixed part. + (when (eq elem 'prefix) + (setq prefix fixed)) + (push prefix res) (push elem res) ;; Extract common suffix additionally to common prefix. ;; Don't do it for `any' since it could lead to a merged diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index df36bce4634..38c2b8c4552 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -306,13 +306,20 @@ completion-substring-test-4 6))) (ert-deftest completion-substring-test-5 () - ;; merge-completions needs to work correctly when + ;; Normally a `prefix' wildcard ignores the common prefix to its + ;; left, since it only grows the common suffix; but if that common + ;; prefix is also a common suffix, it should be included. (should (equal - (completion-pcm--merge-completions '("ab" "sab") '(prefix "b")) - '("b" "a" prefix))) + (completion-pcm--merge-try '(prefix "b") '("ab" "sab") "" "") + '("ab" . 2))) (should (equal - (completion-pcm--merge-completions '("ab" "ab") '(prefix "b")) - '("b" "a"))) + (completion-pcm--merge-try '(prefix "b") '("ab" "ab") "" "") + '("ab" . 2))) + ;; When there's a fixed string before `prefix', that fixed string + ;; should always be included. + (should (equal + (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "") + '("ab" . 2))) ;; substring completion should successfully complete the entire string (should (equal (completion-substring-try-completion "b" '("ab" "ab") nil 0) -- 2.39.3 --=-=-=--