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 and subdirectories matching grep-find-ignored-directories are skipped in the marked directories.

REGEXP should use constructs supported by your local grep command.

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): ")
  (require 'grep)
  (require 'xref)
  (defvar grep-find-ignored-files)
  (declare-function rgrep-find-ignored-directories "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))
         (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)))
               (nreverse marks))
              (message "Searching...")
              (setq xrefs
                    (xref-matches-in-files regexp files))
              (unless xrefs
                (user-error "No matches for: %s" regexp))
              (message "Searching...done")
              xrefs))))
    (xref--show-xrefs fetcher nil)))