Function: dired-do-find-regexp

dired-do-find-regexp is an autoloaded, interactive and byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-do-find-regexp REGEXP)

Documentation

Find all matches for REGEXP in all marked files.

If no files are marked, use the file under point.

For any marked directory, all of its files are searched recursively. However, files matching grep-find-ignored-files(var)/grep-find-ignored-files(fun) and subdirectories matching grep-find-ignored-directories are skipped in the marked directories.

REGEXP should use constructs supported by your local grep command.

View in manual

Probably introduced at or before Emacs version 25.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;;###autoload
(defun dired-do-find-regexp (regexp)
  "Find all matches for REGEXP in all marked files.

If no files are marked, use the file under point.

For any marked directory, all of its files are searched recursively.
However, files matching `grep-find-ignored-files' and subdirectories
matching `grep-find-ignored-directories' are skipped in the marked
directories.

REGEXP should use constructs supported by your local `grep' command."
  (interactive "sSearch marked files (regexp): " dired-mode)
  (require 'grep)
  (require 'xref)
  (declare-function rgrep-find-ignored-directories "grep" (dir))
  (declare-function grep-find-ignored-files "grep" (dir))
  (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 default-directory)))
         (fetcher
          (lambda ()
            (let (files xrefs)
              (mapc
               (lambda (mark)
                 (if (file-directory-p mark)
                     (setq files (nconc
                                  (project--files-in-directory mark ignores "*")
                                  files))
                   (push mark files)))
               (reverse marks))
              (message "Searching...")
              (setq xrefs
                    (xref-matches-in-files regexp files))
              (unless xrefs
                (user-error "No matches for: %s" regexp))
              (message "Searching...done")
              xrefs))))
    (dired-post-do-command)
    (xref-show-xrefs fetcher nil)))