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.
This commit is contained in:
Spencer Baugh 2026-07-22 09:58:56 -04:00 committed by Sean Whitton
parent db6beef260
commit 287187f202
2 changed files with 16 additions and 5 deletions

View file

@ -4773,9 +4773,19 @@ the same set of elements."
(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.

View file

@ -312,11 +312,12 @@
'("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