emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 ccd7cd2 3/3: Speed up dired-do-find-regexp


From: Dmitry Gutov
Subject: emacs-27 ccd7cd2 3/3: Speed up dired-do-find-regexp
Date: Thu, 26 Dec 2019 10:41:05 -0500 (EST)

branch: emacs-27
commit ccd7cd2c51c8a3755b084f93ae3a66a3df8a42f0
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Speed up dired-do-find-regexp
    
    * lisp/dired-aux.el (dired-do-find-regexp): Speed up (bug#36857).
    Previously, 'find' was called for every marked file (for plain
    files and directories both).  Now 'find' is only called for
    directories.
---
 lisp/dired-aux.el | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index fb1ad62..ce967b0 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2957,6 +2957,8 @@ with the command \\[tags-loop-continue]."
 
 (declare-function xref--show-xrefs "xref")
 (declare-function xref-query-replace-in-results "xref")
+(declare-function project--files-in-directory "project")
+(declare-function project--find-regexp-in-files "project")
 
 ;;;###autoload
 (defun dired-do-find-regexp (regexp)
@@ -2975,19 +2977,24 @@ REGEXP should use constructs supported by your local 
`grep' command."
   (require 'xref)
   (defvar grep-find-ignored-files)
   (declare-function rgrep-find-ignored-directories "grep" (dir))
-  (let* ((files (dired-get-marked-files nil nil nil nil t))
+  (let* ((marks (dired-get-marked-files nil nil nil nil t))
          (ignores (nconc (mapcar
                           #'file-name-as-directory
                           (rgrep-find-ignored-directories default-directory))
                          grep-find-ignored-files))
          (fetcher
           (lambda ()
-            (let ((xrefs (mapcan
-                          (lambda (file)
-                            (xref-collect-matches regexp "*" file
-                                                  (and (file-directory-p file)
-                                                       ignores)))
-                          files)))
+            (let (files xrefs)
+              (mapc
+               (lambda (mark)
+                 (if (file-directory-p mark)
+                     (setq files (nconc
+                                  (project--files-in-directory mark ignores 
"*")
+                                  files))
+                   (push mark files)))
+               (nreverse marks))
+              (setq xrefs
+                    (project--find-regexp-in-files regexp files))
               (unless xrefs
                 (user-error "No matches for: %s" regexp))
               xrefs))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]