Dired always read file system

* dired.el (dired-always-read-filesystem): Add new option.
(dired-mark-files-containing-regexp): Use it (Bug#22694).
* doc/emacs/dired.texi: Mention it in the manual.
* test/lisp/dired-tests.el (dired-test-bug22694): Add test.
;* etc/NEWS: Add entry for this change.
This commit is contained in:
Tino Calancha 2016-07-11 14:34:49 +09:00
parent bfeda891a5
commit df7774be39
4 changed files with 48 additions and 5 deletions

View file

@ -550,13 +550,16 @@ Mark (with @samp{*}) all files whose @emph{contents} contain a match for
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
will look in the buffer without revisiting the file, so the results
name. Note that if a file is visited in an Emacs buffer,
and @code{dired-always-read-filesystem} is @code{nil} (the default), this
command will look in the buffer without revisiting the file, so the results
might be inconsistent with the file on disk if its contents has changed
since it was last visited. If you don't want this, you may wish
reverting the files you have visited in your buffers, or turning on
the @code{auto-revert} mode in those buffers, before invoking this
command. @xref{Reverting}.
command. @xref{Reverting}. If you prefer that this command always revisit
the file, without having to revert the file or enable @code{auto-revert}
mode, you might want to set @code{dired-always-read-filesystem} to non-@code{nil}.
@item C-/
@itemx C-x u

View file

@ -242,6 +242,14 @@ whose content matches a regexp; bound to '% g'.
** Dired
+++
*** A New option 'dired-always-read-filesystem' default to nil.
If non-nil, buffers visiting files are reverted before search them;
for instance, in 'dired-mark-files-containing-regexp' a non-nil value
of this option means the file is revisited in a temporary buffer;
this temporary buffer is the actual buffer searched: the original buffer
visiting the file is not modified.
+++
*** In wdired, when editing files to contain slash characters,
the resulting directories are automatically created. Whether to do

View file

@ -255,6 +255,18 @@ new Dired buffers."
:version "24.4"
:group 'dired)
(defcustom dired-always-read-filesystem nil
"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 in a temporary buffer before searching
them: the search is performed on the temporary buffer, the original
buffer visiting the file is not modified."
:type 'boolean
:version "25.2"
:group 'dired)
;; Internal variables
(defvar dired-marker-char ?* ; the answer is 42
@ -3359,7 +3371,8 @@ object files--just `.o' will mark more than you might think."
A prefix argument means to unmark them instead.
`.' and `..' are never marked.
Note that if a file is visited in an Emacs buffer, this command will
Note that if a file is visited in an Emacs buffer, and
`dired-always-read-filesystem' is nil, this command will
look in the buffer without revisiting the file, so the results might
be inconsistent with the file on disk if its contents has changed
since it was last visited."
@ -3379,7 +3392,7 @@ since it was last visited."
(message "Checking %s" fn)
;; For now we do it inside emacs
;; Grep might be better if there are a lot of files
(if prebuf
(if (and prebuf (not dired-always-read-filesystem))
(with-current-buffer prebuf
(save-excursion
(goto-char (point-min))

View file

@ -31,5 +31,24 @@
(symbol-function
'dired-jump))))
(ert-deftest dired-test-bug22694 ()
"Test for http://debbugs.gnu.org/22694 ."
(let* ((dir (expand-file-name "bug22694" default-directory))
(file "test")
(full-name (expand-file-name file dir))
(regexp "bar")
(dired-always-read-filesystem t))
(make-directory dir)
(with-temp-file full-name (insert "foo"))
(find-file-noselect full-name)
(dired dir)
(with-temp-file full-name (insert "bar"))
(dired-mark-files-containing-regexp regexp)
(unwind-protect
(should (equal (dired-get-marked-files nil nil nil 'distinguish-1-mark)
`(t ,full-name)))
;; Clean up
(delete-directory dir 'recursive))))
(provide 'dired-tests)
;; dired-tests.el ends here