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#74420: 31.0.50; PCM completion for ~/src/emacs/trunk/*/minibuf breaks Date: Mon, 18 Nov 2024 12:36:19 -0500 Message-ID: References: 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="8538"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: monnier@iro.umontreal.ca To: 74420@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 18 18:38:24 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 1tD5he-00026q-Da for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Nov 2024 18:38:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD5gd-0008HS-Qb; Mon, 18 Nov 2024 12:37:19 -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 1tD5gO-0008CU-78 for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 12:37:04 -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 1tD5gN-0004ma-3p for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 12:37:03 -0500 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=1o++/63SWWwB2EVcNVVJu144sXdfEkBhofJlEw6KuqE=; b=g8kjmdOkRZUrs3oV351DvH6+6tfHfFPsX4r2kqy0TwM38/ReAS0IU49N4qvj7C4m6Si+2/pOJl6rxn1VcV1zNYr9g2kLWYB2avU7fKZElaNSHIjFmN+GkhcM2HydW6qb+p+duuj+wothheftU1I93Kmkf7iMtBIHc26IykEUenOLOt8t/E0/x4mUyPs4003FCp3pw+8gswU4gBovaVN8USpyM4iOX3SXLgMLq1XYHsg/66w867glAAMylW7AfabMgKuHIRpZTi1c3PCXbfpXwVsWTLR/xf+Z3Nz9SlhXo0UAwxSZoaEZgnVbiNjqjV9WZkE90/N5NmEpQYcS3tq7ZQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tD5gM-0005zh-4w for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 12:37: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: Mon, 18 Nov 2024 17:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74420 X-GNU-PR-Package: emacs Original-Received: via spool by 74420-submit@debbugs.gnu.org id=B74420.173195138922986 (code B ref 74420); Mon, 18 Nov 2024 17:37:02 +0000 Original-Received: (at 74420) by debbugs.gnu.org; 18 Nov 2024 17:36:29 +0000 Original-Received: from localhost ([127.0.0.1]:35038 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tD5fp-0005yg-7a for submit@debbugs.gnu.org; Mon, 18 Nov 2024 12:36:29 -0500 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:33469) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tD5fk-0005yO-O8 for 74420@debbugs.gnu.org; Mon, 18 Nov 2024 12:36:28 -0500 In-Reply-To: (Spencer Baugh's message of "Mon, 18 Nov 2024 12:33:00 -0500") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1731951379; bh=1o++/63SWWwB2EVcNVVJu144sXdfEkBhofJlEw6KuqE=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=TImcRMW4XGn+oNCnI//OA2fv3rMOE+ZNxdhk3Zjm0FN2uhvMlVqKFYpralT13qje3 m7pU15L+3zufN8BNoM43xPeteHS7gxYl/GSfomq5NRpJ3bdFkuUSncHreyOaDUrmZH ntgR9kCm/HgnuMaKuNY7s8jyIH5Z92C/g0+PwE0xR5DELvje76RIuLAiXzSJLmkNI4 W505fZzGj9pEvn37HMkUgrvlv5N+vSzh3Z8zCskAxxQ7rbt91upzLhwvi2yNRSyRnT mGMgKnzVXx3T2/g6Rt56636NBNPjQBjGTIPtITO0N+QHLHYfZPZKDgdsLzTOMzsPCH C49HkEhIx8nZw== 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:295605 Archived-At: --=-=-= Content-Type: text/plain Patch to fix this: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Preserve-an-explicit-in-pcm-try-completion.patch >From d7377eb6abfc57552f43687aec358934b33707e6 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Mon, 18 Nov 2024 12:26:55 -0500 Subject: [PATCH] Preserve an explicit * in pcm-try-completion An explicitly typed * has different semantics from automatically inserted PCM wildcards, so it should be preserved on try-completion. We already do this in some cases, but now we do it more. Concretely, we do it by optimizing the PCM pattern more aggressively to avoid having multiple wildcards in a row: after those are removed, the existing code in completion-pcm--merge-completions is able to preserve * in more cases. The additional optimization should also improve performance. This is especially significant for filename completion: removing an explicit * can take us from ~/src/emacs/trunk/*/minibuf to ~/src/emacs/trunk//minibuf The explicit double slash is interpreted by the file name completion table to mean "start completing from the root directory", so deleting the * here substantially changes semantics. * lisp/minibuffer.el (completion-pcm--optimize-pattern): Add more optimizations. (bug#74420) (completion-pcm--find-all-completions): Optimize the pattern after concatenating two subpatterns. * test/lisp/minibuffer-tests.el (completion-pcm--optimize-pattern) (completion-pcm-test-7): Add tests. --- lisp/minibuffer.el | 20 ++++++++++++++++---- test/lisp/minibuffer-tests.el | 30 +++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 5f3f5d3ead1..e48d85b777d 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4073,8 +4073,18 @@ completion-pcm--optimize-pattern (let ((n '())) (while p (pcase p - (`(,(or 'any 'any-delim) ,(or 'any 'point) . ,_) - (setq p (cdr p))) + ;; Remove duplicate `any' and `prefix' + (`(any any . ,rest) + (setq p (cons 'any rest))) + (`(prefix prefix . ,rest) + (setq p (cons 'prefix rest))) + ;; `any' matches anything `any-delim' does, and grows the same way. + (`(any-delim any . ,rest) + (setq p (cons 'any rest))) + ;; Remove other wildcards found around `star' or `point'. + ((or `(,(and keep (or 'star 'point)) ,(or 'any 'any-delim 'prefix) . ,rest) + `(,(or 'any 'any-delim 'prefix) ,(and keep (or 'star 'point)) . ,rest)) + (setq p (cons keep rest))) ;; This is not just a performance improvement: it turns a ;; terminating `point' into an implicit `any', which affects ;; the final position of point (because `point' gets turned @@ -4445,8 +4455,10 @@ completion-pcm--find-all-completions ;; (dolist (submatch suball) ;; (push (concat submatch between newsubstring) all))) )) - (setq pattern (append subpat (list 'any (string sep)) - (if between (list between)) pattern)) + (setq pattern + (completion-pcm--optimize-pattern + (append subpat (list 'any (string sep)) + (if between (list between)) pattern))) (setq prefix subprefix))) (if (and (null all) firsterror) (signal (car firsterror) (cdr firsterror)) diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 38c2b8c4552..d988a2007cb 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -133,7 +133,19 @@ completion-pcm--optimize-pattern (should (equal (completion-pcm--optimize-pattern '("buf" point "f")) '("buf" point "f"))) (should (equal (completion-pcm--optimize-pattern '(any "" any)) - '(any)))) + '(any))) + (should (equal (completion-pcm--optimize-pattern '(any-delim "" any)) + '(any))) + (should (equal (completion-pcm--optimize-pattern '(prefix "" prefix)) + '(prefix))) + (should (equal (completion-pcm--optimize-pattern '(prefix star any)) + '(star))) + (should (equal (completion-pcm--optimize-pattern '(any point prefix "foo")) + '(point "foo"))) + ;; The `any' and `prefix' are erased because they're next to `point', + ;; then `point' is erased because it's at the end. + (should (equal (completion-pcm--optimize-pattern '(any point prefix)) + '()))) (defun test-completion-all-sorted-completions (base def history-var history-list) (with-temp-buffer @@ -258,6 +270,22 @@ completion-pcm-test-6 (car (completion-pcm-all-completions "li-pac*" '("do-not-list-packages") nil 7))))) +(ert-deftest completion-pcm-test-7 () + ;; Wildcards are preserved even when right before a delimiter. + (should (equal + (completion-pcm-try-completion + "x*/" + '("x1/y1" "x2/y2") + nil 3) + '("x*/y" . 4))) + ;; This is important if the wildcard is at the start of a component. + (should (equal + (completion-pcm-try-completion + "*/minibuf" + '("lisp/minibuffer.el" "src/minibuf.c") + nil 9) + ("*/minibuf" . 9)))) + (ert-deftest completion-substring-test-1 () ;; One third of a match! (should (equal -- 2.39.3 --=-=-=--