Tuesday, October 19, 2010

rgrep on windows 7 for emacs

I lost an hour configuring this, so seems worthy of a blog post.

A fresh install of emacs for windows will have functionality that does not work because it depends on unix style utilities.

One very useful example is the command rgrep, which searches files recursively through subfolders looking for a regular expression in those files.

Under the hood it uses the unix command line tools find, and egrep. Unfortunately the windows version of find takes entirely different parameters and will not function. In fact you will get an error that looks like this:

FIND: Wrong parameter format

Using the set of native ports of Unix command line tools UnxUtils you can easily fix this:

  1. Download the zip file and extract it to c:\unxutils
  2. Add the following path to the very front of your path by editing your system environment variables C:\unxutils\usr\local\wbin\;
That's it. You can run rgrep now and hopefully you're up and running.

If not make sure you have restarted emacs so it picks up the new setting of PATH. Open a shell in emacs and type 'find --version'. You should see something like this if your path is configured correctly:

c:\find --version
find --version
GNU find version 4.1

and if not you will see:

C:\Windows\system32>find --help
FIND: Parameter format not correct


Jérôme Radix said...

Thx for this tip.

You could also use Gnuwin32.

Justin said...

Yeah I used that previously. It has a lot more programs available. I think unxutils is easier to set up since it's a one click download.

Anonymous said...

And of course if you have Cygwin installed, you can use that.

The Emacs Wiki has information on integrating Emacs and Cygwin.

Justin said...

Yes but with purely native solutions you don't have to worry about weird Cygwin paths in emacs, and the performance is better, at least in theory.