GNU bug report logs - #78719
30.1; [PATCH] Add functions `string-common-prefix' and `string-try-completion'

Previous Next

Package: emacs;

Reported by: Phil Sainty <psainty <at> orcon.net.nz>

Date: Sun, 8 Jun 2025 12:05:01 UTC

Severity: normal

Tags: patch

Found in version 30.1

Full log


Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: Phil Sainty <psainty <at> orcon.net.nz>
Cc: bug-gnu-emacs <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Drew Adams <drew.adams <at> oracle.com>, juri <at> linkov.net
Subject: Re: 30.1; [PATCH] Add functions `string-common-prefix' and
 `string-try-completion'
Date: Sun, 08 Jun 2025 14:21:52 +0200
Phil Sainty <psainty <at> orcon.net.nz> 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




This bug report was last modified 5 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.