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

From: Stephen Berman <[email-masked]>
Date: Tue, 29 Apr 2025 12:19:11 +0200

On Mon, 28 Apr 2025 14:01:18 -0400 Stefan Monnier <[email-masked]> wrote:

>> But actually there's a simpler and better way to do that: just duplicate
>> all the $s to $$, then substitute-in-file-name turns all the $$ back to
>> $ without expanding environment variables.  So I did that in the
>> attached updated patch.
>
> LGTM, pushed to `master`.

This patch causes two regressions wrt emacs-30.  One I pointed out
upthread (<[email-masked]>,
<https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-04/msg00884.html>).
For this, the following patch fixes the regression according to my
testing:
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index f8593fde0f7..cf5ab39bfb2 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4609,7 +4609,7 @@ completion-pcm--merge-completions
                                 (mapcar (lambda (str) (substring str skip))
                                         comps))))))
                       (cl-assert (stringp suffix))
-                      (unless (equal suffix "")
+                      (unless (member suffix '("" "/"))
                         (push suffix res))))
                   ;; We pushed these wildcards on RES, so we're done with them.
                   (setq wildcards nil))

For the other regression, here is a reproducer:

0. mkdir /tmp/{Test,retest}
1. emacs -Q --eval "(custom-set-variables                        \
   '(completion-category-overrides '((file (styles substring)))) \
   '(read-file-name-completion-ignore-case t))"
2. Type `C-x d /tmp/tes TAB': this completes to /tmp/test/
3. Type TAB again: Emacs dings and shows "[no match]"

If you repeat this recipe in emacs-30, then after the TAB in step 3, this
completion is shown: /tmp/Test/. and typing TAB again pops up the
*Completions* buffer displaying the two completions ../ and ./

While the result in emacs-30 seems suboptimal, since it omits the
possible completion /tmp/retest/, still it's better than "[no match]".

A workaround for both emacs-30 and master is to enter at step 2 `C-x d
/tmp/*tes TAB'. This shows the completion /tmp/*test/, then hitting TAB
again shows /tmp/*test/., and hitting TAB a third time pops up the
*Completions* buffer showing the four completions Test/../, Test/./,
retest/../, and retest/./

Steve Berman