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

From: Daniel Mendler <[email-masked]>
Date: Wed, 18 Jun 2025 14:17:43 +0200

Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> On Wed, 18 Jun 2025 01:00:31 +0200 Stephen Berman <[email-masked]> wrote:
>
>> On Tue, 17 Jun 2025 15:26:36 -0400 Spencer Baugh <[email-masked]> wrote:
>>
>>> Stephen Berman <[email-masked]> writes:
>>>
>>>> On Tue, 17 Jun 2025 10:59:56 -0400 Spencer Baugh <[email-masked]> wrote:
>> [...]
>>> This is the behavior of the substring completion style.  When there's a
>>> common substring between all the completions,
>>> completion-substring-try-completion inserts that substring.  Since the
>>> substring is a common suffix, it positions point before that common
>>> suffix.
>> [...]
>>> To have only "substring" configured as a completion style implies you
>>> want the behavior of the "substring" completion style, and only that
>>> behavior.  You are indeed getting that behavior.  What's the problem?
>>> substring has always behaved like this, so improved consistency in edge
>>> cases like this one should not be a surprise.
>>
>> You may consider this an edge case, but it is proof that the substring
>> style has not "always behaved like this".  I don't recall that the goal
>> of "improved consistency in edge cases" was previously cited in this
>> thread; if it had been, I might have viewed the issue in a different
>> light, though I still find the current behavior problematic...
>>
>>> Is there some problem with this behavior, some reason it doesn't work
>>> right for you?  A more concrete complaint about what doesn't work would
>>> be helpful.
>>
>> ...to wit:
>>
>> Before your change, when using substring style, typing `C-x d /us TAB
>> TAB' completes to "/usr/" and pops up the *Completions* buffer.  If I
>> want to change the input, e.g. to "/var/", I can type `M-DEL va TAB'.
>>
>> After your change, when using substring style, typing `C-x d /us TAB
>> TAB' completes to "/usr//" and only after typing TAB a third time does
>> the *Completions* buffer pop up.  If I want to change the input, typing
>> `M-DEL' has no effect, though e.g. `C-f / va TAB' works (the minibuffer
>> then displays "~//usr//var/" with "~//usr/" in file-name-shadow face).
>> It works, but it's a bit more cumbersome than previously (an extra TAB
>> to get the *Completions* buffer) and visually confusing (at least given
>> familiarity with the previous behavior).
>>
>> And again, with my patch (posted in
>> https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-04/msg01860.html)
>> I get the behavior and appearance I'm used to, and for my usage have
>> encountered no problems with it.  I ask you once again: please tell me
>> specifically what problems that patch causes.
>
> Assuming the current behavior of substring completion in master is not a
> bug/regression but the intended "improved consistency", I would like to
> propose a different patch (attached) to make the completion behavior
> conditional on a user option, defaulting to the current behavior in
> master.

Can we please avoid adding absurd user options like
`completion-/-not-common-suffix'? The completion machinery is already
complex with many options. Adding options for minor details does not
seem like a good direction.

Daniel