reddit / emacs

Use ripgrep or ag in project.el?

shmulkinator · 2022-05-25 14:39
Is it possible to use `ripgrep` or `ag` in `project.el` for finding matches in files? I looked around a bit and don't see how that can be done, but that may say more about my Google/Elisp-fu than the ability to do that.
_viz_ · 2022-05-25 15:28
From a quick glance at project.el, it relies on xref for C-x p g (project-find-regexp). So you need to customise xref-search-program I suppose.
cark · 2022-05-25 16:48
If by any chance you are using helm. It has an helm-projectile-ag command which i occasionally use to good effect. If not, maybe you could look into its source code and see how it works.
grimscythe_ · 2022-05-25 16:58
This. Alternatively helm-do-ag and select the root folder from where the search begins.
shmulkinator · 2022-05-25 17:05
Thanks for the suggestion. For better or worse, I don't use helm.
s-kostyaev · 2022-05-25 17:05
With `rg.el` you can do something like this: ``` (rg-define-search my-grep-project :query ask :format regexp :files "everything" :case-fold-search smart :dir (if (project-current) (project-root (project-current)) default-directory) :confirm prefix :flags ("--hidden -g !.git")) ``` You can use it like `M-x` `my-grep-project` `<RET>` or bind it to some keys.
wargxs · 2022-05-25 17:29
I recommend https://github.com/leoliu/ack-el or the build in vc-git-grep which should be faster for git projects
Foo-jin · 2022-05-25 17:32
I use the excellent `consult` package for this; have a look at [`consult-ripgrep`](https://github.com/minad/consult#grep-and-find)
dpassen1 · 2022-05-25 18:56
Can confirm this works. I don’t believe there’s support for `ag` but `ripgrep` is a valid option.
Ghosty141 · 2022-05-25 22:56
This has been the best way to do project wide grep for me. Really fast and easily customizeable.
LuisHGH · 2022-05-26 00:30
Ripgrep by default ignores git files, no? I remember reading something like this
burntsushi · 2022-05-26 00:36
It respects your gitignore, ignores hidden files and binary files by default. Like ag. You can disable all smart filtering with -uuu.
_viz_ · 2022-05-26 03:49
You just need to add a suitable entry in xref-search-program-alist. EDIT: If my memory serves me right, ag support was added recently by Manuel Uberti.