Subject: [PATCH] Insert * on TAB with completion-pcm-leading-wildcard=t

From: Spencer Baugh <[email-masked]>
Date: Mon, 11 Aug 2025 12:44:12 -0400

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/'

>From 0c13bd0b3de0cd7f2f06e304cf7d578f93fe4343 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Wed, 9 Apr 2025 14:01:05 -0400
Subject: [PATCH] Insert * on TAB with completion-pcm-leading-wildcard=t

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.

* lisp/minibuffer.el (completion-pcm--string->pattern): Add
'star wildcard, not just 'prefix.
---
 lisp/minibuffer.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 1d1e07faf70..632e111ecc8 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4197,7 +4197,7 @@ completion-pcm--string->pattern
               (setq p0 p)
             (push (substring string p (match-end 0)) pattern)
             ;; `any-delim' is used so that "a-b" also finds "array->beginning".
-            (setq pending (if completion-pcm-leading-wildcard 'prefix 'any-delim))
+            (setq pending (if completion-pcm-leading-wildcard 'star 'any-delim))
             (setq p0 (match-end 0))))
         (setq p p0))
 
@@ -4207,7 +4207,7 @@ completion-pcm--string->pattern
       (setq pattern (nreverse pattern))
       (when completion-pcm-leading-wildcard
         (when (stringp (car pattern))
-          (push 'prefix pattern)))
+          (push 'star pattern)))
       pattern)))
 
 (defun completion-pcm--optimize-pattern (p)
-- 
2.39.3