]> code.delx.au - gnu-emacs/commitdiff
Dired always read file system
authorTino Calancha <tino.calancha@gmail.com>
Mon, 11 Jul 2016 05:34:49 +0000 (14:34 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Mon, 11 Jul 2016 05:34:49 +0000 (14:34 +0900)
* 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
etc/NEWS
lisp/dired.el
test/lisp/dired-tests.el

index 486e92a40bbbad0fc5907c168bc4b170dc9846fb..2cda51a82fa1b9bbf9e619a5710944659c2de5db 100644 (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
index 6aef73a3c963c3d9f3b94c21d2ad47a552823232..c58349cd4ec9807839774b741806c7371a702acf 100644 (file)
--- 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
index d078478aaaff1c616dc5b2228c066059db2532f3..5d14291d787bede4536686c12ff546bf8d87e559 100644 (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))
index 3efe2599138d2c915fa2bfe379ba8eaade2f89bf..d66a9caedd3fe8f18264ef4304aaaf4cfa9b3258 100644 (file)
     (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