bug#81394: 31.0.90; unexpected buffer completion behavior

Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]> Mon, 03 Aug 2026 14:29:14 -0400
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
--=-=-=
Content-Type: text/plain

Eli Zaretskii <[email protected]> writes:

> Ping!  Spencer, could you please fix the test, so this change could
> be installed?

Oops, yes, fixed.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0001-pcm-try-completion-collapse-into.patch

From 308079f8fbaa74dfae90d91840960011499e1f0f Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email protected]>
Date: Wed, 22 Jul 2026 09:58:56 -0400
Subject: [PATCH] pcm-try-completion: collapse ** into *

* lisp/minibuffer.el (completion-pcm--merge-completions): Only
include one star in the return value. (bug#81394)
* test/lisp/minibuffer-tests.el (completion-pcm-test-7): Update
for new behavior.
---
 lisp/minibuffer.el            | 16 +++++++++++++---
 test/lisp/minibuffer-tests.el |  5 +++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index aa6e8686d9c..a7cc04e32ce 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4795,9 +4795,19 @@ completion-pcm--merge-completions
                     (setq prefix (substring prefix 0 (length fixed))))
                   (push prefix res)
                   ;; Push all the wildcards in this stretch, to preserve `point' and
-                  ;; `star' wildcards before ELEM.
-                  (dolist (wildcard wildcards)
-                    (push wildcard res))
+                  ;; `star' wildcards before ELEM.  Collapse multiple `star's down to one
+                  ;; on each side of point. (bug#81394)
+                  (let ((star-seen nil))
+                    (dolist (wildcard wildcards)
+                      (cond
+                       ((eq wildcard 'star)
+                        (unless star-seen
+                          (push 'star res))
+                        (setq star-seen t))
+                       (t
+                        (when (eq wildcard 'point)
+                          (setq star-seen nil))
+                        (push wildcard res)))))
                   ;; Extract common suffix additionally to common prefix.
                   ;; Don't do it for `any' since it could lead to a merged
                   ;; completion that doesn't itself match the candidates.
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index 59ae6ae3758..cd59d201109 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -312,11 +312,12 @@ completion-pcm-test-7
             '("lisp/minibuffer.el" "src/minibuf.c")
             nil 9)
            '("*/minibuf" . 9)))
-  ;; A series of wildcards is preserved (for now), along with point's position.
+  ;; A series of `star's is collapsed into a single one, but point's
+  ;; position is preserved in the middle. (bug#81394)
   (should (equal
            (completion-pcm--merge-try
             '(star star point star "foo") '("xxfoo" "xyfoo") "" "")
-           '("x***foo" . 3)))
+           '("x**foo" . 2)))
   ;; The series of wildcards is considered together; if any of them wants the common suffix, it's generated.
   (should (equal
            (completion-pcm--merge-try
-- 
2.43.7


--=-=-=--