Subject: bug#73635: dired-do-query-replace-regexp should check if files are selected first

From: Eli Zaretskii <[email-masked]>
Date: Sat, 26 Oct 2024 09:59:39 +0300

> From: Dan Jacobson <[email-masked]>
> Cc: Visuwesh <[email-masked]>,  [email-masked]
> Date: Sat, 26 Oct 2024 05:53:14 +0800
> 
> >> > E.g., yes there were files selected, but we just did a first run, and
> >> > are no longer looking at the dired buffer. We need to go back to the
> >> > dired buffer first. Fine. But at least let the user know before they
> >> > bother entering the from and to values.
> >> 
> >> It uses the filename under point if there are no marked files like all
> >> dired commands.
> 
> EZ> Right, and so I think there's no bug here to fix, and I'm therefore
> EZ> closing it.
> 
> There is no check that the user is staring at the dired buffer first
> before asking for the two strings.

When this command is invoked, it prompts thusly:

  Query replace regexp in marked files:

Which already says that files should be marked before they could be
query-replaced.

> In fact what needs to be changed is:
> dired-do-query-replace-regexp needs to first check if the current buffer
> is a dired buffer.

That already happens if you invoke with "M-X" (capital X) or if you
customize read-extended-command-predicate to
command-completion-default-include-p.  We just decided not to make
that the default yet.

> And if it is not, it needs to say "Must be run in a dired buffer" and
> quit.
> 
> (Even if there is only one dired buffer in buffer-list.)

I see no reason to complicate the command to cover such made-up
scenarios.  If and when we decide to make
command-completion-default-include-p the default, this will happen
automatically.