unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* project-find-regexp using ripgrep
@ 2020-06-14 21:30 Dmitry Gutov
  2020-06-18  9:49 ` Ergus
  2020-06-20  1:06 ` Dmitry Gutov
  0 siblings, 2 replies; 14+ messages in thread
From: Dmitry Gutov @ 2020-06-14 21:30 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

Here's a small patch I've been toying with, inspired by bug#41766.

In my testing, it makes the project search an order of magnitude faster. 
Probably due to smart parallelization.

If people confirm this experience, I'm going to install it (or something 
similar), even though, well, it would be nice to consolidate this search 
tool into something smarter, and done in one package only. But that for 
the future.

How to try:

- M-x project-find-regexp in your favorite project.
- If you're feeling scientific, evaluate something like

    (benchmark 1 '(project-find-regexp "grep-regexp-alist"))

- Change the argument to something else if you're searching something 
other than the Emacs project.
- Try it a couple of times.
- Note the reported timings.

- Install ripgrep (e.g. with 'apt install ripgrep').
- Apply the patch.
- [Rebuild], restart Emacs.
- Repeat the first several steps.

[-- Attachment #2: xref-ripgrep.diff --]
[-- Type: text/x-patch, Size: 1895 bytes --]

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 <C> -nH --no-messages -g '!*/' -e <R>"
+  ;"xargs -0 grep <C> -snHE -e <R>"
+  )
+
 ;;;###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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-12-09 21:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14 21:30 project-find-regexp using ripgrep Dmitry Gutov
2020-06-18  9:49 ` Ergus
2020-06-18  9:55   ` Dmitry Gutov
2020-06-18 10:20     ` Ergus
2020-06-20  1:06 ` Dmitry Gutov
2020-06-20  4:09   ` andres.ramirez
2020-06-22  0:01     ` Dmitry Gutov
2020-06-22  2:30       ` Eli Zaretskii
2020-06-22 13:10         ` Dmitry Gutov
2020-06-22 14:53           ` Eli Zaretskii
2020-06-22  3:12       ` andrés ramírez
2020-12-04  1:56         ` Dmitry Gutov
2020-12-09  4:14           ` andrés ramírez
2020-12-09 21:46             ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).