(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)
(push mark files)))
(nreverse marks))
(setq xrefs
- (project--find-regexp-in-files regexp files))
+ (xref-matches-in-files regexp files))
(unless xrefs
(user-error "No matches for: %s" regexp))
xrefs))))
(declare-function grep-read-files "grep")
(declare-function xref--show-xrefs "xref")
(declare-function xref--find-ignores-arguments "xref")
-(declare-function xref--regexp-to-extended "xref")
-(declare-function xref--convert-hits "xref")
;;;###autoload
(defun project-find-regexp (regexp)
nil)))
(defun project--find-regexp-in-files (regexp files)
- (pcase-let*
- ((output (get-buffer-create " *project grep output*"))
- (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
- (status nil)
- (hits nil)
- (xrefs nil)
- ;; Support for remote files. The assumption is that, if the
- ;; first file is remote, they all are, and on the same host.
- (dir (file-name-directory (car files)))
- (remote-id (file-remote-p dir))
- ;; 'git ls-files' can output broken symlinks.
- (command (format "xargs -0 grep %s -snHE -e %s"
- (if (and case-fold-search
- (isearch-no-upper-case-p regexp t))
- "-i"
- "")
- (shell-quote-argument (xref--regexp-to-extended regexp)))))
- (when remote-id
- (setq files (mapcar #'file-local-name files)))
- (with-current-buffer output
- (erase-buffer)
- (with-temp-buffer
- (insert (mapconcat #'identity files "\0"))
- (setq default-directory dir)
- (setq status
- (project--process-file-region (point-min)
- (point-max)
- shell-file-name
- output
- nil
- shell-command-switch
- command)))
- (goto-char (point-min))
- (when (and (/= (point-min) (point-max))
- (not (looking-at grep-re))
- ;; TODO: Show these matches as well somehow?
- (not (looking-at "Binary file .* matches")))
- (user-error "Search failed with status %d: %s" status
- (buffer-substring (point-min) (line-end-position))))
- (while (re-search-forward grep-re nil t)
- (push (list (string-to-number (match-string line-group))
- (match-string file-group)
- (buffer-substring-no-properties (point) (line-end-position)))
- hits)))
- (setq xrefs (xref--convert-hits (nreverse hits) regexp))
+ (let ((xrefs (xref-matches-in-files regexp files)))
(unless xrefs
(user-error "No matches for: %s" regexp))
xrefs))
#'xref-matches-in-directory
"27.1")
+;;;###autoload
+(defun xref-matches-in-files (regexp files)
+ "Find all matches for REGEXP in FILES.
+Return a list of xref values.
+FILES must be a list of absolute file names."
+ (pcase-let*
+ ((output (get-buffer-create " *project grep output*"))
+ (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
+ (status nil)
+ (hits nil)
+ ;; Support for remote files. The assumption is that, if the
+ ;; first file is remote, they all are, and on the same host.
+ (dir (file-name-directory (car files)))
+ (remote-id (file-remote-p dir))
+ ;; 'git ls-files' can output broken symlinks.
+ (command (format "xargs -0 grep %s -snHE -e %s"
+ (if (and case-fold-search
+ (isearch-no-upper-case-p regexp t))
+ "-i"
+ "")
+ (shell-quote-argument (xref--regexp-to-extended regexp)))))
+ (when remote-id
+ (setq files (mapcar #'file-local-name files)))
+ (with-current-buffer output
+ (erase-buffer)
+ (with-temp-buffer
+ (insert (mapconcat #'identity files "\0"))
+ (setq default-directory dir)
+ (setq status
+ (project--process-file-region (point-min)
+ (point-max)
+ shell-file-name
+ output
+ nil
+ shell-command-switch
+ command)))
+ (goto-char (point-min))
+ (when (and (/= (point-min) (point-max))
+ (not (looking-at grep-re))
+ ;; TODO: Show these matches as well somehow?
+ (not (looking-at "Binary file .* matches")))
+ (user-error "Search failed with status %d: %s" status
+ (buffer-substring (point-min) (line-end-position))))
+ (while (re-search-forward grep-re nil t)
+ (push (list (string-to-number (match-string line-group))
+ (match-string file-group)
+ (buffer-substring-no-properties (point) (line-end-position)))
+ hits)))
+ (xref--convert-hits (nreverse hits) regexp)))
+
(defun xref--rgrep-command (regexp files dir ignores)
(require 'find-dired) ; for `find-name-arg'
(defvar grep-find-template)