Subject: Re: bug#70217: [PATCH] Add substring-partial-completion style

From: Daniel Mendler <[email-masked]>
Date: Fri, 17 May 2024 00:09:54 +0200

Spencer Baugh <[email-masked]> writes:

> Stefan Monnier <[email-masked]> writes:
>
>>> * lisp/minibuffer.el (completion-emacs22-use-pcm)
>>> (completion-substring-use-pcm): Add. (bug#70217)
>>> (completion-emacs22-try-completion)
>>> (completion-emacs22-all-completions): Check completion-emacs22-use-pcm.
>>> (completion-pcm--string->pattern, completion-pcm--find-all-completions)
>>> (completion-pcm-all-completions, completion-pcm--merge-try)
>>> (completion-pcm-try-completion): Add "startglob" optional argument and
>>> pass through.
>>> (completion-substring-try-completion)
>>> (completion-substring-all-completions): Check
>>> completion-substring-use-pcm and pass startglob=t.
>>
>> I'm not super happy about this `startglob` everywhere.
>> Two things bother me about it:
>>
>> - Its name and doc (in my view of what "glob" means, there's no such
>>   thing as a "leading glob"; I think you're talking about a leading
>>   wildcard (which is one of the things that can appear in a glob
>>   pattern)).
>
> Yes, very true, changed to "anchored".
>
>> - Its spreading all over the place.
>
> In the attached diff it's a dynamic variable completion-pcm-anchored
> checked in one place.  How's that?
>
>> I don't have the time to dig into the second problem (which might be
>> fixable by combining this info into the `string` argument (which
>> wouldn't be just a string as more, so it could have too-far reaching
>> consequences)), but for the first I suspect a "standard" name for this
>> idea is `anchored`.
>>
>> Other than that, I don't have a strong opinion on whether to introduce
>> the feature via new styles or as custom vars that affect
>> existing styles.  Either way works for me.
>
> As part of making it a dynamic variable, I also changed the usage.  In
> the attached diff, an element in completion-styles can contain
> additional dynamic variable bindings:
>
> (setq completion-styles '(basic (partial-completion (completion-pcm-anchored nil)) emacs22))
>
> This is powerful and elegant in some ways - for example now a user could
> use completion-ignore-case only for an individual style.  Also, the
> overall diff is now much shorter.

This sounds great. It will also be useful in other settings. For example
the Orderless completion style can be configured via a bunch of dynamic
variables. Right now, in orderless.el we provide the helper macro
`orderless-define-completion-style' which creates a derived completion
style with a bunch of let-bound dynamic variables. Your new feature will
make it easier and more direct to configure custom derived completion
styles.

Daniel