Subject: Re: bug#78719: 30.1; [PATCH] Add functions `string-common-prefix' and `string-try-completion'

From: Daniel Mendler <[email-masked]>
Date: Mon, 09 Jun 2025 12:56:42 +0200

Stefan Monnier <[email-masked]> writes:

>> I think it is confusing if the function respects the
>> `completion-regexp-list' and `completion-ignore-case' dynamic
>> variables,
>
> Strong agreement, here.  It's arguably already a problem to use those
> dynbound variables in `try-completion`, so it's even worse here for
> a function which wants to be unrelated to completion.

Yes, exactly. I always wondered why these variables are dynamic, since I
think of them as additional arguments to `try-completion' and
`all-completions'. Historical reasons? Would it make sense to change
their calling convention, or do you feel that such a change would be too
intrusive? Probably it is not worth the effort. But in any case, we
should avoid the mistake for the new function in the string namespace.

>> and if we end up with three functions
>> `try-completion', `string-try-completion', and
>> `completions-try-completion'.
>>
>> Why not only provide a single function `string-expand-prefix' with
>> additional keyword or optional arguments:
>>
>> (cl-defun string-common-prefix (strings &key ignore-case regexps predicate))
>
> The "try completion" part of the name sounds like it's motivated by the
> historical accident of how we got to it, so if we want to help those
> who're not familiar with (or thinking about) completion, a name like
> `string-common-prefix` sounds better, indeed.

+1

> Do we have reasons to believe callers will want/need those `&key`
> arguments?  My gut tells me we don't need the `predicate` and
> `regexps` options.

Yes, I think it makes sense to only offer the simplest function without
additional features, since the goal is a simpler API after all to obtain
common prefixes.

(defun string-common-prefix (strings &key ignore-case))

If additional completion features are needed, we can refer the user to
`try-completion' in the docstring or the manual.

>         Stefan