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

From: Phil Sainty <[email-masked]>
Date: Tue, 03 Jun 2025 23:37:57 +1200

Hi Drew,

Thank you for:

>     (let ((common  (try-completion "" files)))

My brain had failed to make the connection between "completion"
and programmatically obtaining a common prefix from list of
strings.  It makes perfect sense in hindsight, but I'd simply
never thought about completion in non-interactive terms, and was
surprised when I hadn't found a documented function for doing
this (but I wasn't looking under Completion at all).

Eli, I reckon this is worth either documenting somewhere under
(info "(elisp) Strings and Characters") or else creating a
slightly more string-centric wrapper, something like:

(defun string-common-prefix (strings)
   "Return the largest common prefix from a list of STRINGS."
   (let ((prefix (try-completion "" strings)))
     (if (stringp prefix)
         prefix
       "")))

(And I now notice that the string shortdoc group *does*
include `try-completion' -- albeit without an example of
using "" for STRING, which I think would be a good addition.)

Regarding the buffer naming:

>>       (dired (cons "MARKED-ANYWHERE"

It hadn't occurred to me that this could be something other
than a directory path.  I definitely agree it would be ideal
not to conflict with other dired buffers, but I've seen some
some oddities from doing it that way.  E.g. after creating
that buffer, I can't obtain it with:

(dired-find-buffer-nocreate "MARKED-ANYWHERE" 'dired-mode)

but rather I need to use:

(dired-find-buffer-nocreate "/path/to/MARKED-ANYWHERE" 'dired-mode)

for the file path it thinks is relevant, which then has some
possibility (albeit unlikely) of conflicting with a real path.

And also (for better or worse) the new command can create extra
MARKED-ANYWHERE buffers under different paths.

We could further reduce the chance of any conflict with an
actual file by choosing an even less-likely name; but perhaps
there's a cleaner solution.

The version I'm currently playing with is attached.  I haven't
tested your version yet, but I've grabbed some of the changes
from the code you've shown.

I've split out a couple of extra functions which felt useful on
their own:

`file-name-directory-common-prefix'
   "The nearest common ancestor directory for FILES."

`dired-get-explicitly-marked-files'
   "Like `dired-get-marked-files' but always returns nil when
  nothing is marked."

-Phil