Subject: Re: bug#78658: 30.1; [PATCH] Dired feature suggestion: dired-on-marked-files-in-all-buffers

From: Daniel Mendler <[email-masked]>
Date: Wed, 04 Jun 2025 10:57:58 +0200

Phil Sainty <[email-masked]> writes:

> On 2025-06-04 08:09, Daniel Mendler wrote:
>> Note that the `completion-styles' only affect
>> `completion-try-completion' and `completion-all-completions', but not
>> the primitive `try-completion', which always computes the common prefix.
>
> Thanks for confirming that.
>
> There are a couple of edge-cases for `try-completion' which made me
> think a new wrapper function for the "find the longest string prefix"
> case would be a good thing, which are:
>
>  (try-completion "" '())
>  nil
>
>  (try-completion "" '(""))
>  t
>
> Hence:
>
>  (defun string-common-prefix (strings)
>   "Return the largest common prefix from a list of STRINGS."
>   (let ((prefix (try-completion "" strings)))
>     (if (stringp prefix)
>         prefix
>       "")))

Note that try-completion can also return `t' and in that case you want
to return the exact string, not the empty string. Also you may want to
bind some completion variables like `completion-regexp-list' and
`completion-ignore-case' to nil (or to an `ignore-case' argument), such
that they do not affect the result. These dynamic variables are not user
settings, but are usually let-bound inside completion style functions
like `completion--pcm-all-completions'. Please take a close look at the
documentation of `try-completion'. In any case, I agree that such a
wrapper would be good to have and easier to use.

Daniel