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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 29 Jun 2025 09:05:55 +0300

> Date: Sun, 29 Jun 2025 15:45:14 +1200
> From: Phil Sainty <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked],
>  [email-masked], [email-masked]
> 
> On 2025-06-11 03:32, Eli Zaretskii wrote:
> >> (string-common-prefix COLLECTION &optional IGNORE-CASE STRING
> >> REGEXP-LIST PREDICATE)
> > 
> > I think STRING should come before IGNORE-CASE.  Otherwise, LGTM,
> > thanks.
> 
> I've pushed the revisions to scratch/string-common-prefix
> 
> After fetching, the revised changes will be:
> 
> git diff master...origin/scratch/string-common-prefix
> 
> 
> My remaining niggle about having STRING before IGNORE-CASE is that
> STRING, REGEXP-LIST, and PREDICATE all fall under the same category
> of "filtering the COLLECTION prior to determining a common prefix",
> so this order interrupts that logical grouping.
> 
> I've described the three filtering arguments together as a group in
> the documentation, for better readability.  I don't mind switching
> the order in the code to match if you change your mind about that;
> otherwise I think this is ready to go, if you don't spot any issues.

If you want to move STRING after IGNORE-CASE, you should rename it to
something like MIN-PREFIX.

Btw, the changes for the manual have the argument list wrong.

Also, this part:

  If COLLECTION contains exactly one string, return that string.

left me wondering whether this will happen even if that single string
doesn't satisfy the filtering criteria.

My single high-level gripe about this changeset is that it ended up to
be too tied up with completion.  AFAIU, the original intent was to
provide an API for finding the longest common prefix of a list of
strings.  With that concept in sight, STRING should have been a
mandatory argument (perhaps an empty string), and the fact that this
is based on the completion machinery should have been an
implementation detail.  The REGEXP-LIST and PREDICATE would not be
needed, either.  By contrast, what we have instead is a variant of
try-completion, and both the documentation and the API itself are
advertising the completion-based nature of the function too loudly to
my palate, starting from the argument named COLLECTION.  Why would we
need yet another variant of try-completion?

So maybe we should make this API simpler, so it could do its main job
without requiring such a large and complicated doc string, and leave
the rest to try-completion?

Thanks.