GNU bug report logs - #79219
[PATCH] Insert * on TAB with completion-pcm-leading-wildcard=t

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Mon, 11 Aug 2025 16:45:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79219 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, dmitry <at> gutov.dev, bug-gnu-emacs <at> gnu.org:
bug#79219; Package emacs. (Mon, 11 Aug 2025 16:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Spencer Baugh <sbaugh <at> janestreet.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, dmitry <at> gutov.dev, bug-gnu-emacs <at> gnu.org. (Mon, 11 Aug 2025 16:45:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Insert * on TAB with completion-pcm-leading-wildcard=t
Date: Mon, 11 Aug 2025 12:44:12 -0400
[Message part 1 (text/plain, inline)]
Tags: patch


Improve completion-pcm-leading-wildcard by actually inserting
a * when try-completion runs.  completion-pcm--merge-try will
automatically remove the wildcard anywhere that it has no
matches, so the * is inserted only where it actually had an
effect.

This makes the behavior more explicit and consistent, and
improves performance in the case where completion-styles is
configured such that we first do partial-completion with
completion-pcm-leading-wildcard=nil, and then fall back to
completion-pcm-leading-wildcard=t: explicitly inserting the *
avoids the need to fallback.

My site has been running with this patch for 4 months now and it's
worked fine.  In my experience it's very useful.

In GNU Emacs 30.1.90 (build 14, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2025-08-11 built on
 igm-qws-u22796a
Repository revision: 2828c98aa29c66798fcb3fa67ccc3ed706024340
Repository branch: emacs-30
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-gsettings --without-selinux --without-imagemagick
 --with-modules --with-gif=no --with-cairo --with-rsvg
 --without-compress-install --with-tree-sitter
 --with-native-compilation=aot
 PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'

[0001-Insert-on-TAB-with-completion-pcm-leading-wildcard-t.patch (text/patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79219; Package emacs. (Fri, 15 Aug 2025 01:35:02 GMT) Full text and rfc822 format available.

Message #8 received at 79219 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Spencer Baugh <sbaugh <at> janestreet.com>, 79219 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#79219: [PATCH] Insert * on TAB with
 completion-pcm-leading-wildcard=t
Date: Fri, 15 Aug 2025 04:34:25 +0300
Spencer, hi,

On 11/08/2025 19:44, Spencer Baugh wrote:
> Improve completion-pcm-leading-wildcard by actually inserting
> a * when try-completion runs.  completion-pcm--merge-try will
> automatically remove the wildcard anywhere that it has no
> matches, so the * is inserted only where it actually had an
> effect.

Would it be difficult to add a test for this?

I can see that you authored some of most recent ones in 
minibuffer-tests.el, but completion-pcm-leading-wildcard does not seem 
to be exercised in our suite yet.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79219; Package emacs. (Mon, 18 Aug 2025 19:02:01 GMT) Full text and rfc822 format available.

Message #11 received at 79219 <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 79219 <at> debbugs.gnu.org
Subject: Re: bug#79219: [PATCH] Insert * on TAB with
 completion-pcm-leading-wildcard=t
Date: Mon, 18 Aug 2025 15:01:32 -0400
[Message part 1 (text/plain, inline)]
Dmitry Gutov <dmitry <at> gutov.dev> writes:

> Spencer, hi,
>
> On 11/08/2025 19:44, Spencer Baugh wrote:
>> Improve completion-pcm-leading-wildcard by actually inserting
>> a * when try-completion runs.  completion-pcm--merge-try will
>> automatically remove the wildcard anywhere that it has no
>> matches, so the * is inserted only where it actually had an
>> effect.
>
> Would it be difficult to add a test for this?
>
> I can see that you authored some of most recent ones in
> minibuffer-tests.el, but completion-pcm-leading-wildcard does not seem
> to be exercised in our suite yet.

Certainly, easy enough to do a basic test, attached.

Though, after working on this some more, I think there's a better thing
to be doing here, which should always apply to pcm rather than be
conditioned on completion-pcm-leading-wildcard: insert a * when a non-*
wildcard is matching against an empty string.

For example, when doing (completion-pcm-try-completion "a/b" '("a/bbb"
"a-test/bbb") nil 3) return "a*/bbb" instead of the current "a/bbb".

This matches up with this comment in completion-pcm--merge-completions:

  ;; 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.

I tried doing that change instead, and it works pretty nicely, but
before landing it I found I had to fix bug#79265 first.  So let's settle
that one first then come back to this bug.

[0001-add-some-leading-wildcard-tests.patch (text/x-patch, inline)]
From e3e8e2f90f33f03127e091388305251d26e5c233 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Mon, 18 Aug 2025 14:51:33 -0400
Subject: [PATCH] add some leading-wildcard tests

---
 test/lisp/minibuffer-tests.el | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index 59b72899e22..2b22ee20b3f 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -332,6 +332,22 @@ completion-pcm-test-8
                   "" '("fooxbar" "fooybar") nil 0)
                  '("foobar" . 3))))
 
+(ert-deftest completion-pcm-test-9 ()
+  ;; By default completions must match the begining of the string.
+  (should (equal (completion-pcm-try-completion
+                  "oo" '("foo") nil 2)
+                 nil))
+  ;; But not with `completion-pcm-leading-wildcard'.
+  (should (equal (let ((completion-pcm-leading-wildcard t))
+                   (completion-pcm-try-completion
+                    "oo" '("foo") nil 2))
+                 '("foo" . 3)))
+  ;; The wildcard is actually inserted into the text.
+  (should (equal (let ((completion-pcm-leading-wildcard t))
+                   (completion-pcm-try-completion
+                    "oo" '("foo" "goo") nil 2))
+                 '("*oo" . 1))))
+
 (ert-deftest completion-substring-test-1 ()
   ;; One third of a match!
   (should (equal
-- 
2.43.7


This bug report was last modified 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.