0

According to the documentation :

(rgrep REGEXP &optional FILES DIR CONFIRM)

Recursively grep for REGEXP in FILES in directory tree rooted at DIR.

[...]

But when I call it in some Elisp code like this :

(rgrep "test" "*\\.org" "\\~/Org")

It ends up neglecting the third argument DIR and instead uses the current directory.

The corresponding output and the find command of the above code is :

-*- mode: grep; default-directory: <current_directory> -*-
Grep started at Fri May  1 14:24:46
find . <exclude_expr> -type f \( -name \*\\.org \) -exec grep --color -i -nH --null -e test \{\} +

but the output I obtained interactively with M-X rgrep

-*- mode: grep; default-directory: ~/Org -*-
Grep started at Fri May  1 14:24:46
find . <exclude_expr> -type f \( -name \*\\.org \) -exec grep --color -i -nH --null -e test \{\} +

is expected.

Note: GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8, cairo version 1.16.0) of 2020-01-13

1

It may be possible that rgrep doesn't automatically expand DIR. Can you try if you have more success with something like that:

(rgrep "test" "*\\.org" (expand-file-name "~/Org"))
| improve this answer | |
  • It's not this, but you helped me find out the problem: I escaped unnecessarily the dir name. – Firmin Martin May 1 at 20:12
1

I haven't made rgrep work at the first time (got an error like string-match("<c>" nil) and still don't know why). I tried to escape unnecessarily the three arguments after reading emacs wiki. But the solution is given for GnuWin32...

Conclusion, when rgrep works, it's as expected: no need to escape anything. I'll ask about the error. No clue why it happens.

EDIT

  1. By Inspecting the rgrep source code, rgrep use default directory when the given one is not a directory (in my case: syntax error).
  2. To prevent string-match("<c>" nil), one must call (grep-compute-defaults) before.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.