Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get grep working in Emacs on Windows (EmacsW32)

M-x grep, M-x lgrep, M-x rgrep don't work in EmacsW32 for me.

I do M-x lgrep and it says grep is not a command:

grep -i -n "hello" * NUL
'grep' is not recognized as an internal or external command,
operable program or batch file.

Grep finished with no matches found at Sun Jan 31 05:59:06

Also what is that NUL thing? EmacsW32 homepage says it ships with Gnuwin32 utilities but it seems the work to configuring to actually use the Gnuwin32 grep is left to users.

How can I configure it to use either the shipped Gnuwin32 grep or the cygwin grep? Are both fine?

like image 461
Yoo Avatar asked Jan 30 '10 21:01

Yoo


1 Answers

This article has some tips on how to get this working.

I got this working the other day, you can set the PATH environment variable inside emacs, and if you have cygwin and/or gnuw32 installed just set the path to those. This is a snippet from my .emacs that's applicable on windows only. I set to variables (cygwin-bin, gnu-bin) to the path where the programs are installed. Then build the path to those. One drawback is it blows away the rest of my path. Which hasn't been an issue so far, but If I was smarter with LISP I could probably figure something out. Anyway, hope this helps.

;;windows only stuff

(when (string-equal system-type "windows-nt")

(progn

(setq cygwin-bin "c:\\apps\\cygwin\\bin")

(setq gnu-bin "C:\\apps\\GnuWin32\\gnuwin32\\bin")

(setenv "PATH"

(concat cygwin-bin ";" gnu-bin ";"))

(setq exec-path

'(cygwin-bin gnu-bin)))) 

I should add, I arrived at this solution because putting qnuwin32 in front of the path in windows seems to be a risky proposition, you run the risk of messing up other programs on your machine. So this seemed to be a good compromise.

like image 154
Tom Willis Avatar answered Oct 27 '22 06:10

Tom Willis