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

From: Dario Gjorgjevski <[email-masked]>
Date: Wed, 25 Nov 2020 09:22:41 +0100

Hi João,

> I took a better look at your patch finally, but I still
> don't understand it fully.

Thanks a lot.  I think the best way to see what’s going on is to take
the ‘completion-pcm--hilit-commonality’ function and, ironically, do
some printf() debugging.  In the current implementation, if you insert

  (message "String: %s" str)            in the initial lambda and
  (message "Found match [%d, %d]" a b)  in ‘update-score’

and then you try the example from the comments

  (completion-flex-all-completions
   "foo" '("fabrobazo" "fbarbazoo" "barfoobaz") nil 3)

you will see it prints

  String: fabrobazo
  Found match [0, 0] [2 times]
  Found match [0, 1]
  Found match [4, 5]
  Found match [9, 9]
  String: fbarbazoo
  Found match [0, 0] [2 times]
  Found match [0, 1]
  Found match [7, 8]
  Found match [9, 9]
  String: barfoobaz
  Found match [0, 0] [2 times]
  Found match [3, 4]
  Found match [4, 5]
  Found match [9, 9]

Notice how the last matching character is *not processed* -- this is the
essence of the bug.  It’s easiest to see from ‘barfoobaz’ where only [3,
4] (the ‘f’) and [4, 5] (the second ‘o’) are processed, [5, 6] is
nowhere to be seen.

With my patch, the output becomes

String: foobarbaz
Found match [0, 1]
Found match [1, 2]
Found match [2, 3]
String: fbarbazoo
Found match [0, 1]
Found match [7, 8]
Found match [8, 9]
String: barfoobaz
Found match [3, 4]
Found match [4, 5]
Found match [5, 6]

Which is all good.

> Don't worry, I will soon.  First thing I looked at
> was the tests you provided, which are very welcome.
> I restructured them, creating instead 13 small tests
> instead of just 3 tests that currently fail.

Thanks a lot once again, this is very appreciated.  Admittedly, the
tests weren’t very good and I wasn’t sure how to make them better.

> I'm the author of one of the commits there and credit
> you as "Co-author".  If you'd rather reverse that, let
> me know.

This is fine by me.

Best regards,
Dario

-- 
$ keyserver=hkps://hkps.pool.sks-keyservers.net
$ keyid=744A4F0B4F1C9371
$ gpg --keyserver $keyserver --search-keys $keyid