Subject: Re: bug#22694: 25.0.91; dired-mark-files-containing-regexp read file disk

From: Eli Zaretskii <[email-masked]>
Date: Sat, 09 Jul 2016 14:07:57 +0300

> From: Tino Calancha <[email-masked]>
> Date: Mon, 27 Jun 2016 00:32:18 +0900 (JST)
> cc: Tino Calancha <[email-masked]>, [email-masked]
> 
> >I guess we could have an option to switch to the behavior you would
> >like to see, but such an option, if we introduce it, IMO should not be
> >specific to this command, it should affect all the Dired commands
> >which might produce different results when buffers are not
> >auto-reverted.
> 
> I have only found another Dired command which might require the new 
> option:
> `dired-do-query-replace-regexp'.
> But it seems unnecessary because this command already alert the user
> if the file has being modified 'externally':
> 
> ./emacs -Q -eval '(progn (with-temp-file "/tmp/foo" (insert "foobar")) (find-file "/tmp/foo") (dired "/tmp"))'
> % g \`foobar$ RET
> M-! echo foo > foo
> M-x dired-do-query-replace-regexp RET \`foobar$ RET bar RET
> ;; File foo changed on disk.  Reread from disk? (yes or no)
> 
> ;;;
> So i propose a patch which:
> 1) Adds a new option `dired-always-read-filesystem' (default value nil).
> 2) Use it just in `dired-mark-files-containing-regexp'.

Thanks, please push to master, after taking care of the following
issues:

> --- a/doc/emacs/dired.texi
> +++ b/doc/emacs/dired.texi
> @@ -550,13 +550,16 @@ Marks vs Flags
>   the regular expression @var{regexp}
>   (@code{dired-mark-files-containing-regexp}).  This command is like
>   @kbd{% m}, except that it searches the file contents instead of the file
> -name.  Note that if a file is visited in an Emacs buffer, this command
> +name.  Note that if a file is visited in an Emacs buffer,
> +and @code{dired-always-read-filesystem} evaluates @code{nil}, this 

Our usual style for what you want to say in the last sentence is like
this:

  Note that if a file is visited in an Emacs buffer, and
  @code{dired-always-read-filesystem} is @code{nil} (the default), ...

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -198,6 +198,9 @@ questions, with a handy way to display help texts.
>   ** Dired
> 
>   +++
> +*** New option 'dired-always-read-filesystem'.

Please tell in a sentence or 2 what does this option do.

> +(defcustom dired-always-read-filesystem nil
> +  "Non-nil means commands like `dired-mark-files-containing-regexp' which
> +may use a buffer visiting the file or read the file on disk, always
> +read the file system.  Otherwise, if do exist a buffer visiting the file,
> +then use that buffer."

The first line of the doc string must be a complete sentence.  So I
suggest the following alternative wording (which also clarifies the
text in other places):

   "Non-nil means revert buffers visiting files before searching them.
 By default,  commands like `dired-mark-files-containing-regexp' will
 search any buffers visiting the marked files without reverting them,
 even if they were changed on disk.  When this option is non-nil, such
 buffers are always reverted before searching them."

> +Note that if a file is visited in an Emacs buffer, and
> +`dired-always-read-filesystem' evaluates nil, this command will
                                  ^^^^^^^^^^^^^
"is nil"

Thanks.

How about a test for this functionality?