Subject: bug#42149: Substring and flex completion ignore implicit trailing ‘any’

From: João Távora <[email-masked]>
Date: Tue, 29 Dec 2020 13:27:05 +0000

João Távora <[email-masked]> writes:

> Stefan Monnier <[email-masked]> writes:
>
>>> I think this elimination of consecutive `any' should also be included in
>>> João’s branch.
>>
>> I just pushed (a rewrite of) that change to `master`.
>
> And I just pushed my cleaned up fix to to master as well, thus hopefully
> fixing the brunt of this bug.  Dario and others, please test this.  I
> haven't yet pushed the tests, since we're not entirely sure of those,
> but I think we should break them up further and push them too, once we
> come to an aggreement on what and how they should test exactly.

Meanwhile, I found that the patch after my sig fixes the remaining two
Dario tests, concerning the presumed misplacement of
'completions-first-difference.

I hadn't touched this part explicitly, and it doesn't seem to make a
world of difference, so I'll leave it up to you two if we should isntall
something like this or not.  (I do think some form of tests should go
in).

I'll put this bit of patch in the side branch
scratch/bug-42149-funny-pcm-completion-scores, too

João

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index dc37c5f447..074d436b35 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3332,11 +3332,12 @@ completion-pcm--hilit-commonality
            ;; for that extra bit of match (bug#42149).
            (unless (= from match-end)
              (funcall update-score-and-face from match-end))
-           (if (> (length str) pos)
-               (add-face-text-property
-                pos (1+ pos)
-                'completions-first-difference
-                nil str))
+           (cl-loop for p from pos below (length str)
+                    unless (eq (get-text-property p 'face str)
+                               'completions-common-part)
+                    return (add-face-text-property p (1+ p)
+                                                   'completions-first-difference
+                                                   nil str))
            (unless (zerop (length str))
              (put-text-property
               0 1 'completion-score