diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 5b5fb4bc47..19fc362ddb 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1246,12 +1246,20 @@ xref-matches-in-directory (declare-function tramp-tramp-file-p "tramp") (declare-function tramp-file-local-name "tramp") +;; '-s' because 'git ls-files' can output broken symlinks. +(defvar xref-grep-template + "xargs -0 rg -nH --no-messages -g '!*/' -e " + ;"xargs -0 grep -snHE -e " + ) + ;;;###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." (cl-assert (consp files)) + (require 'grep) + (defvar grep-highlight-matches) (pcase-let* ((output (get-buffer-create " *project grep output*")) (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist)) @@ -1261,13 +1269,12 @@ xref-matches-in-files ;; 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))))) + ;; The 'auto' default would be fine too, but ripgrep can't handle + ;; the options we pass in that case. + (grep-highlight-matches) + (command (grep-expand-template xref-grep-template + (xref--regexp-to-extended regexp) + regexp))) (when remote-id (require 'tramp) (setq files (mapcar