Function: xref-matches-in-directory
xref-matches-in-directory is an autoloaded and byte-compiled function
defined in xref.el.gz.
Signature
(xref-matches-in-directory REGEXP FILES DIR IGNORES &optional DELIMITED)
Documentation
Find all matches for REGEXP in directory DIR.
Return a list of xref values.
Only files matching some of FILES and none of IGNORES are searched.
FILES is a string with glob patterns separated by spaces.
IGNORES is a list of glob patterns for files to ignore.
If DELIMITED is symbol, only select matches that span full symbols.
Probably introduced at or before Emacs version 28.1.
Aliases
xref-collect-matches (obsolete since 27.1)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/xref.el.gz
;;;###autoload
(defun xref-matches-in-directory (regexp files dir ignores &optional delimited)
"Find all matches for REGEXP in directory DIR.
Return a list of xref values.
Only files matching some of FILES and none of IGNORES are searched.
FILES is a string with glob patterns separated by spaces.
IGNORES is a list of glob patterns for files to ignore.
If DELIMITED is `symbol', only select matches that span full symbols."
;; DIR can also be a regular file for now; let's not advertise that.
(grep-compute-defaults)
(defvar grep-find-template)
(defvar grep-highlight-matches)
(pcase-let*
((grep-find-template (replace-regexp-in-string "<C>" "<C> -E"
grep-find-template t t))
(grep-highlight-matches nil)
;; TODO: Sanitize the regexp to remove Emacs-specific terms,
;; so that Grep can search for the "relaxed" version. Can we
;; do that reliably enough, without creating false negatives?
(command (xref--rgrep-command (xref--regexp-to-extended regexp)
files
"."
ignores))
(local-dir (directory-file-name
(file-name-unquote
(file-local-name (expand-file-name dir)))))
(hits-regexp (if (eq delimited 'symbol)
(format "\\_<%s\\_>" regexp)
regexp))
(buf (get-buffer-create " *xref-grep*"))
(`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
(status nil)
(hits nil))
(with-current-buffer buf
(erase-buffer)
(setq default-directory dir)
(setq status
(process-file-shell-command command nil t))
(setq hits (xref--parse-hits grep-re line-group file-group status
local-dir)))
(xref--convert-hits (xref--sort-hits hits) hits-regexp)))