From df7774be39af76d3072a0278ef815a47bf50dfe9 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Mon, 11 Jul 2016 14:34:49 +0900 Subject: [PATCH] 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. --- doc/emacs/dired.texi | 9 ++++++--- etc/NEWS | 8 ++++++++ lisp/dired.el | 17 +++++++++++++++-- test/lisp/dired-tests.el | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 486e92a40b..2cda51a82f 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 6aef73a3c9..c58349cd4e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 diff --git a/lisp/dired.el b/lisp/dired.el index d078478aaa..5d14291d78 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -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)) diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el index 3efe259913..d66a9caedd 100644 --- a/test/lisp/dired-tests.el +++ b/test/lisp/dired-tests.el @@ -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 -- 2.39.2