all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: emacs-devel <emacs-devel@gnu.org>
Subject: project-find-regexp using ripgrep
Date: Mon, 15 Jun 2020 00:30:08 +0300	[thread overview]
Message-ID: <49f66d46-da8d-9658-ec85-ced39a99ad87@yandex.ru> (raw)

[-- 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

             reply	other threads:[~2020-06-14 21:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14 21:30 Dmitry Gutov [this message]
2020-06-18  9:49 ` project-find-regexp using ripgrep 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49f66d46-da8d-9658-ec85-ced39a99ad87@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.