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

From: Eli Zaretskii <[email-masked]>
Date: Sat, 07 Jun 2025 13:19:04 +0300

> From: Drew Adams <[email-masked]>
> CC: "[email-masked]" <[email-masked]>,
>         "[email-masked]"
> 	<[email-masked]>,
>         "[email-masked]" <[email-masked]>,
>         "[email-masked]" <[email-masked]>,
>         "[email-masked]"
> 	<[email-masked]>, "[email-masked]" <[email-masked]>
> Date: Thu, 5 Jun 2025 21:25:13 +0000
> 
> When `dired-mode' is invoked it calls `dired-advertise',
> which adds the Dired buffer to the value of global variable
> `dired-buffers'.  A couple commands remove a buffer name from
> this list, by calling `dired-unadvertise'.  In particular,
> `wdired-change-to-wdired-mode' does this, because it changes
> the major mode from `dired-mode' to `wdired-mode'.
> 
> The value of var `dired-buffers' is thus generally a list of
> all buffers in `dired-mode'.  (This can include buffers that
> have been killed, so filtering with `buffer-live-p' is also
> needed.)
> 
> The only exceptions are (1) commands `find-dired' and its
> derivatives such as `find-name-dired', and (2) commands
> `find-lisp-dired*'.  They're exceptions because they bind
> `dired-buffers' around their work (see above), so as not to
> add their resulting Dired buffers to `dired-buffers'.
> 
> This means that code can't just examine `dired-buffers' to
> find the set of Dired buffers (buffers advertised to be in
> `dired-mode').  Instead, it needs to filter `buffer-list',
> to gather the buffers with modes derived from `dired-mode'.
> That's unfortunate - it's much more costly, in general.
> 
> The question is whether there's a good reason why find*
> buffers, which are in `dired-mode', should be excluded from
> being "advertised" as such, i.e., whether they should really
> be excluded from `dired-buffers'.  And if so, why?
> 
> It was apparently a 1998 commit by Richard that added the
> protective binding to `find-dired', but with no comment as
> to why.
> 
> In the Emacs sources, at least, there are no other places
> that exclude `dired-mode' buffers from `dired-buffers'.
> And grepping for `find-dired' shows that there are no places
> that rely on such exclusion for `find-dired' buffers.  Same
> for `find-lisp-find-dired-internal' (which binds
> `dired-buffers' for `find-lisp*').

Thanks.

If we allow find-dired to add its buffers to the list in
dired-buffers, we need to make sure they are removed from the list.
We also need to make sure that functions which scan the list and
operate on its buffers will DTRT with find-dired buffers found in the
list.  Is all of this reasonable to do, and if so, is it planned to be
done as part of the changes you are discussing?