Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lgrep and rgrep in Emacs

Tags:

grep

emacs

I am having problems with the greps in Emacs.

a) grep doesnt seem to understand the .[ch] for searching .c and .h files. This is a default option provided by Emacs with the lgrep command. The example is searching for the word "global" in .c/.h files.

grep -i -nH "global" *.[ch]
grep: *.[ch]: No such file or directory

Grep exited abnormally with code 2 at Mon Feb 16 19:34:36

Is this format not valid?

b) Using rgrep I get the following error:

find . "(" -path "*/CVS" -o -path "*/.svn" -o -path "*/{arch}" -o -path "*/.hg" -o -path "*/_darcs" -o -path "*/.git" -o -path "*/.bzr" ")" -prune -o  -type f "(" -iname "*.[ch]" ")" -print0 | xargs -0 -e grep -i -nH "global"
FIND: Wrong parameter format

Grep finished (matches found) at Mon Feb 16 19:37:10

I am using Emacs 22.3.1 on Windows XP with the GNU W32 Utils (grep, find, xargs etc.). Grep v2.5.3 and find v4.2.20.

What am I missing?

UPDATE:

Too bad one can't accept multiple answers...since the solution to my problems are spread out.

grep -i -nH "global" *.c *.h

This solves the first problem. Thanks luapyad!

(setq find-program "c:\\path\\to\\gnuw32\\find.exe")

emacs was indeed using the Windows find.exe. Forcing the gnu32 find fixed the second problem. Thanks scottfrazer.

However, I still like ack best.

like image 335
cschol Avatar asked Feb 17 '09 02:02

cschol


2 Answers

I found out that using:

(setq find-program "\"C:/path/to/GnuWin32/bin/find.exe\"")
(setq grep-program "\"C:/path/to/GnuWin32/bin/grep.exe\"")

Works better in windows, since you could have a space laying around the path and will screw up eventually.

Notice I used the two programs in my .emacs file.

Hope it's of some help to some other programmer in need ;)

like image 87
oscarcardoso Avatar answered Sep 29 '22 18:09

oscarcardoso


Well, there is always Ack and Ack.el

like image 27
elmarco Avatar answered Sep 29 '22 19:09

elmarco