1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-24 05:22:04 -08:00

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.
This commit is contained in:
Dmitry Gutov 2019-12-26 17:39:48 +02:00
parent 7edb1f0773
commit ccd7cd2c51

View file

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