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

From: Daniel Mendler <[email-masked]>
Date: Sun, 08 Jun 2025 14:21:52 +0200

Phil Sainty <[email-masked]> writes:

> This is a spin-off from bug#78658 -- and following on from
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78658#65 in particular --
> to add friendlier alternatives to `try-completion' for efficiently
> obtaining a common string prefix or completion from a collection of
> strings outside of the context of minibuffer completion.
>
> E.g. when you simply want to know the longest common prefix from a
> list of strings without having to deal with any completion variables
> or edge-case return values.
>
> Unlike `try-completion' which may return nil or t, the new functions
> always return a string, simplifying their usage and (on account of
> the "string-*" naming) making the functionality more discoverable
> for programmers working with strings.
>
> The function `string-try-completion' provides the general case and
> is just like `try-completion' except for always returning a string.

What is the purpose of having a separate function
`string-try-completion'? I think it is confusing if the function
respects the `completion-regexp-list' and `completion-ignore-case'
dynamic variables, 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 STRING or initial prefix argument seems redundant, since one can
always use the empty string, and use `string-prefix-p' to check a
desired prefix, or am I missing something?

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

Daniel