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#72819: [PATCH] Correctly include fixed strings before a prefix wildcard in PCM Date: Mon, 26 Aug 2024 10:17:05 -0400 Message-ID: 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="26610"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca To: 72819@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 26 16:18:32 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 1siaYB-0006kr-2W for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 26 Aug 2024 16:18:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siaXt-0002F7-9T; Mon, 26 Aug 2024 10:18:13 -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 1siaXr-0002Et-F7 for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 10:18:11 -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 1siaXr-0002KV-1h for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 10:18:11 -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:From:To:Subject; bh=gIIuSo/xXlBoXGiDf+KMWclxDRD4341NdH1eO2vsw60=; b=bxb84fTuqrujrHFeFksOyieY4TQuXqh1KJKv/Cjy6tYg2maL8MZL4ACRT6ELv6P7bbHgIP4EcwsaO5370eI7gZqmDq31bIk4quMPWsR06HAVKv/YXrOkmwCLqoqnlcQoJi4wPq/Nq2W7x3KN7m2kE8zk3KetGRswVENUhkDtFHaVNXcnFfAZtcTrm4+LKHT9W2JYKzJ1nt1nDv9lvNiqOojSDusD+yptgKfuWjO41GziQzmy0waE2oRrq565alB/1zzox5qSlQukz5e4PB0y/5Ueg1wIoDKb4KUxaBfGOJbPf+dofAb49/dnGRxZItI5oVYb8bmQ5RGVCWabqSbqjg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1siaYg-0007MA-5B for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 10:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Aug 2024 14:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72819 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172468188428195 (code B ref -1); Mon, 26 Aug 2024 14:19:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Aug 2024 14:18:04 +0000 Original-Received: from localhost ([127.0.0.1]:45022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1siaXj-0007Kg-GF for submit@debbugs.gnu.org; Mon, 26 Aug 2024 10:18:04 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:60846) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1siaXh-0007KH-5H for submit@debbugs.gnu.org; Mon, 26 Aug 2024 10:18:01 -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 1siaWr-00021Z-In for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 10:17:09 -0400 Original-Received: from mxout6.mail.janestreet.com ([64.215.233.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1siaWp-0002HJ-Px for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 10:17:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1724681826; bh=gIIuSo/xXlBoXGiDf+KMWclxDRD4341NdH1eO2vsw60=; h=From:To:Cc:Subject:Date; b=eMn+Xw5Qizu2OjoFh3q3oiv1ysgS78sIv7nC1ZCeCZ5i3jccPvSVNMyz58Hed50aJ 0S7LIdv0K0plUQd5i4wtFPR+sdlnOu+iW0kbB/K3XSJHszPB14tjT5bTQiE2GAeU2d bA82rQsuAhm76orzNiYSgpMM7GmYsym+l7zhQocwvz/LWZgflf0TX3j6EBWT59PUj6 GFWVijyi5WjW13ahlqRcJUiPep+cYJSEjC00/pmqsS0UZ0rqxJpfSNSRvRKADTZwCY IhQbUjvpQjIQhbdikfXjU5V4QOdi4Dkfzo2sfau+NwkCBDO8RZzFEv7aEfNiIr0xJm vG1M4RlGp2kmQ== Received-SPF: pass client-ip=64.215.233.21; envelope-from=sbaugh@janestreet.com; helo=mxout6.mail.janestreet.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:290784 Archived-At: --=-=-= Content-Type: text/plain Tags: patch In 63a48252306a631dc07d62d19311433c7877bd27 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. In GNU Emacs 29.2.50 (build 12, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-08-23 built on igm-qws-u22796a Repository revision: 253525ba4598f487e451b93a4ab1680ef212a62d Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --with-x-toolkit=lucid --without-gpm --without-gconf --without-selinux --without-imagemagick --with-modules --with-gif=no --with-cairo --with-rsvg --without-compress-install --with-native-compilation=aot --with-tree-sitter PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Correctly-include-fixed-strings-before-a-prefix-wild.patch >From 6d7a8f5e491e4ba4eb6e0026278b4df3d70a4a83 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 63a48252306a631dc07d62d19311433c7877bd27 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): * test/lisp/minibuffer-tests.el (completion-substring-test-5): --- 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 --=-=-=--