2

How can we customize Emacs' rgrep to use ripgrep (rg executable) -- making it working for searching in Latin 1, UTF-8 and UTF-16 at the same time?

The idea is to reuse the standard rgrep command of Emacs, so that we can use next-error and previous-error as well...

I don't see how to fully integrate the (for the base dir) and the (for the files matched) specifiers, among others.

(grep-apply-setting 'grep-find-template
                    "rg -uu -g <F> <R> <D>")

will produce (when searching within *.txt files)

rg -uu -g \( -iname \*.txt \) test .
error: Invalid value for '--max-count <NUM>': invalid digit found in string

Grep exited abnormally with code 1 at Sun Aug  6 00:23:58
user3341592
  • 1,419
  • 1
  • 17
  • 36
  • `rg` doesn't support `find` predicates. Just normal globbing. You have to combine it with the `find` command. – Jürgen Hötzel Aug 06 '17 at 10:01
  • @JürgenHötzel Thanks for the info. Could you show how to write it then (and publish it as an answer)? – user3341592 Aug 06 '17 at 12:20
  • There are two packages in melpa that work with ripgrep: `rg` and `ripgrep`. I'm trying out `rg` now, because it says it supports `wgrep-ag`; `wgrep` is one of my favorite features. – jpkotta Aug 07 '17 at 17:07

1 Answers1

2

grep-find-template is for using a grepcommand in combination with find. This works for me:

(grep-apply-setting 'grep-find-template "find <D> <X> -type f <F> -exec rg <C> --no-heading -H  <R> /dev/null {} +")

If you want to use rg without find you have to use lgrep and customize:

(grep-apply-setting 'grep-template "rg --no-heading -H -uu -g <F> <R> <D>")
Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58
  • Thanks. To what should grep-command and grep-find-command be set, for rg? – user3341592 Aug 06 '17 at 20:11
  • Got a "Search failed. This means there is unmatched expression somewhere or we are at the beginning/end of file." when testing M-x rgrep. I don't understand the + sign at the end of your string. Is that right? – user3341592 Aug 06 '17 at 20:14
  • The `+` is part of `find` syntax. It defines the end of the `exec` action. – Jürgen Hötzel Aug 07 '17 at 17:18
  • Your solution (dunno what happened the first time) or `(grep-apply-setting 'grep-find-template "find -type f -exec rg --no-heading -H /dev/null {} \\;")` almost work for me: message `/dev/null: The system cannot find the file specified. (os error 2)` is displayed between the command and the results (in the `*grep*` buffer). And matches are not displayed in color anymore. Any idea what's wrong? Thanks! – user3341592 Aug 09 '17 at 15:54
  • In fact, the message about `/dev/null` appears between results as well - it's part of them. For some reason... – user3341592 Aug 09 '17 at 15:55
  • I doubt that makes a diff, but I'm on Cygwin (Emacs and shell). – user3341592 Aug 09 '17 at 15:56
  • Removing the `/dev/null` from your string does remove the first line with the error message... Why was that needed? – user3341592 Sep 05 '17 at 20:23
  • With the above command, I get no color for the matched text -- while we do in a shell prompt. Is there something special to do to get it? – user3341592 Sep 05 '17 at 20:24