Subject: Re: bug#77718: 31.0.50; completion styles substring and flex are broken

From: Spencer Baugh <[email-masked]>
Date: Fri, 11 Apr 2025 09:03:12 -0400

Eli Zaretskii <[email-masked]> writes:
>> Date: Fri, 11 Apr 2025 00:22:01 +0200
>> From:  Stephen Berman via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> 0. Start Emacs like this:
>> 
>>    emacs -Q --eval "(custom-set-variables '(completion-category-overrides '((file (styles substring)))))"
>> 
>>    or like this:
>> 
>>    emacs -Q --eval "(custom-set-variables '(completion-category-overrides '((file (styles flex)))))"
>> 
>> 1. Type `C-x d' and at the prompt enter: `/usr/ TAB'.
>> => Now the text following the prompt is this: "/usr//" and "/usr/" is
>> fontified with face file-name-shadow.
>> 
>> 2. Type `TAB' again.
>> => Now the text following the prompt is this: "//" and the first forward
>> slash is fontified with face file-name-shadow.
>> 
>> 3. Type `TAB' again.
>> => Now a *Completions* buffer pops up listing all the directories
>> directly under root (dev/, etc/, home/ and so on).
>> 
>> This only happens with the substring and flex completion styles; with
>> any of the other completion styles (basic, partial-completion, emacs22,
>> initials), or if Emacs is started just with -Q, then after step 1 as
>> expected a *Completions* buffer pops up listing the directories under
>> /usr (bin/, include/, lib/ and so on).
>> 
>> The broken behavior with the substring and flex styles is due to the
>> change in completion-pcm--merge-completions in this commit:
>> 
>> commit 0fbba16387513e7692b46885833e4a9c218251f0
>> Author:     Spencer Baugh <[email-masked]>
>> Commit:     Stefan Monnier <[email-masked]>
>> CommitDate: Tue Apr 8 14:36:30 2025 -0400
>> 
>>   Preserve an explicit * in pcm-try-completion
>>   [...]
>>   * lisp/minibuffer.el (completion-pcm--merge-completions): Don't drop
>>   important wildcards. (bug#74420)

Thanks for the detailed bug report.

Reduced slightly, the issue is that
  (completion-pcm--merge-completions '("x/" "y/") '(prefix))
now returns 
  ("/" any prefix "" "")
when it used to return
  (any "" "")

I think this may be related to the implict "any" added by
completion-pcm--merge-completions.  I'll look into it and find a fix
(and add a test covering this case).