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

From: Daniel Mendler <[email-masked]>
Date: Sat, 05 Jul 2025 14:35:06 +0200

Phil Sainty <[email-masked]> writes:

>> 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?
>
> If `string-common-prefix' was not based on `try-completion' and we
> needed to write all of the functionality from scratch, then I would
> not be pushing to include and document the additional features.
>
> It is based on `try-completion' though (for the good reason that
> `try-completion' is already extremely efficient at performing this
> task), and that has some ramifications for the new function:
>
> 1. It will support the same COLLECTION data types as `try-collection'.
>
> 2. All of the filtering features of `try-collection' are available.
>
> I just see no reason to hide or suppress any of these things.  Each of
> the filtering options may very well prove useful to users -- and they
> are already implemented!  I don't know why we wouldn't provide access
> to them.  It may be a somewhat advanced option feature set, but it's
> not an /unreasonable/ feature set for this function to have -- each
> filter would be useful in different circumstances, so it seems to me
> like a perfectly useful thing to support, and it's so easy to do so.

Yes, it is very easy to expose all the details of the underlying
implementation. But why are we even adding this function then? If the
function only replicates everything already provided then there is no
value in adding it. Only changing the return type to string is not worth
the addition of a new function.

Good API design is also about curation. This means to make a good choice
about provided functionality and the arguments. The goal here was to
provide a simple function to compute the common prefix of a list of
strings (possibly respecting case sensitivity). The other arguments go
beyond that purpose.

Daniel