Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is it possible to run rgrep in emacs on Win32?

194 views
Skip to first unread message

Steinar Bang

unread,
Apr 12, 2012, 5:21:41 AM4/12/12
to help-gn...@gnu.org
Platform: emacs 23.2.1,
GnuWin32 FindUtils 4.2.20-2
GnuWin32 Grep-2.5.4

Does anyone know of a way to make the emacs rgrep command work on
windows?

I'm trying to run `M-x rgrep RET' on a windows emacs. I have installed
find and grep from GnuWin32 ( http://gnuwin32.sourceforge.net/ ) and put
them early in the PATH.

When I try to run rgrep it exits with no match, and in the *grep* I see
the following error message:
C:\ProgramFiles\GnuWin32\bin\find: invalid expression; I was expecting to find a ')' somewhere but did not see one.

The command line is:
C:\ProgramFiles\GnuWin32\bin\find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "*/{arch}" ")" -prune -o "(" -name ".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak" -o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o -name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name "*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name "*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name "*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name "*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name "*.x86f" -o -name "*.sparcf" -o -name "*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name "*.pfsl" -o -name "*.dfsl" -o -name "*.p64fsl" -o -name "*.d64fsl" -o -name "*.dx64fsl" -o -name "*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name "*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name "*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o -type f "(" -iname "*.csproj" ")" -print0 | xargs -0 -e grep -i -nH -e "searchterm"

Parantheses seems to be balanced...? I haven't installed xargs, I
think... unless that's part of FindUtils...?

Tassilo Horn

unread,
Apr 12, 2012, 4:39:57 AM4/12/12
to help-gn...@gnu.org
Steinar Bang <s...@dod.no> writes:

Hi Steinar,

> When I try to run rgrep it exits with no match, and in the *grep* I see
> the following error message:
> C:\ProgramFiles\GnuWin32\bin\find: invalid expression; I was expecting to find a ')' somewhere but did not see one.
>
> The command line is:
> C:\ProgramFiles\GnuWin32\bin\find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "*/{arch}" ")" -prune -o "(" -name ".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak" -o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o -name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name "*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name "*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name "*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name "*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name "*.x86f" -o -name "*.sparcf" -o -name "*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name "*.pfsl" -o -name "*.dfsl" -o -name "*.p64fsl" -o -name "*.d64fsl" -o -name "*.dx64fsl" -o -name "*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name "*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name "*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o -type f "(" -iname "*.csproj" ")" -print0 | xargs -0 -e grep -i -nH -e "searchterm"
>
> Parantheses seems to be balanced...?

Yes, and the command works just fine on a GNU/Linux box...

> I haven't installed xargs, I think... unless that's part of
> FindUtils...?

It's part of GNU findutils, and the Win32 FindUtils say so, too:

http://gnuwin32.sourceforge.net/packages/findutils.htm

Does it work if you provide the full patch to xargs in the command line,
e.g., C:\ProgramFiles\GnuWin32\bin\xargs?

Bye,
Tassilo


Eli Zaretskii

unread,
Apr 12, 2012, 5:29:19 AM4/12/12
to help-gn...@gnu.org
> From: Steinar Bang <s...@dod.no>
> Date: Thu, 12 Apr 2012 11:21:41 +0200
>
> Platform: emacs 23.2.1,
> GnuWin32 FindUtils 4.2.20-2
> GnuWin32 Grep-2.5.4

What version of Windows is that?

> Does anyone know of a way to make the emacs rgrep command work on
> windows?

First, try Emacs 23.3 or later, there were some changes made there to
fix problems with very long command lines, perhaps you are hitting
that limit. If that doesn't help, maybe advice below will.

"M-x rgrep" works for me on Windows XP, but I use Fiindutils that I
built myself, as the GnuWin32 provided port is broken (in particular,
xargs is affected). You can find my port here:

http://sourceforge.net/projects/ezwinports/files/

However, lately someone told me that my build doesn't work well on
Windows Vista and later, because Microsoft changed the way quoted
wildcards are processed by the startup code that globs them: now
wildcards are globbed even if they are quoted. If you are using such
a new version of Windows, the only solution I know of is to downgrade
to an even older version 4.1 of Findutils from here:

http://unxutils.sourceforge.net/

I think someone told me that this port does work on newer Windows
versions.

HTH

Thierry Volpiatto

unread,
Apr 12, 2012, 6:07:25 AM4/12/12
to help-gn...@gnu.org
I suggest you use https://github.com/emacs-helm/helm
which work out of the box with recursive grep and doesn't need find and
xargs, only Gnuwin32 grep >=2.5.4.

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997


Steinar Bang

unread,
Apr 12, 2012, 11:26:03 AM4/12/12
to help-gn...@gnu.org
>>>>> Eli Zaretskii <el...@gnu.org>:

> What version of Windows is that?

2008 Server R2 SP1.

> First, try Emacs 23.3 or later, there were some changes made there to
> fix problems with very long command lines, perhaps you are hitting
> that limit.

Thanks! Will try!

> If that doesn't help, maybe advice below will.

> "M-x rgrep" works for me on Windows XP, but I use Fiindutils that I
> built myself, as the GnuWin32 provided port is broken (in particular,
> xargs is affected). You can find my port here:

> http://sourceforge.net/projects/ezwinports/files/

Thanks again! Will look at this one as well.

> However, lately someone told me that my build doesn't work well on
> Windows Vista and later,

2008 R2 will qualify there. It is on the same generation as Win7 I
think...?

> because Microsoft changed the way quoted wildcards are processed by
> the startup code that globs them: now wildcards are globbed even if
> they are quoted. If you are using such a new version of Windows, the
> only solution I know of is to downgrade to an even older version 4.1
> of Findutils from here:

> http://unxutils.sourceforge.net/

> I think someone told me that this port does work on newer Windows
> versions.

Ok. Will try this one as well if none of the above works.

Thanks!

Eli Zaretskii

unread,
Apr 12, 2012, 10:13:06 AM4/12/12
to help-gn...@gnu.org
> From: Steinar Bang <s...@dod.no>
> Date: Thu, 12 Apr 2012 17:26:03 +0200
>
> > However, lately someone told me that my build doesn't work well on
> > Windows Vista and later,
>
> 2008 R2 will qualify there. It is on the same generation as Win7 I
> think...?

Yes, it is.

Evgeniy Dolzhenko

unread,
Apr 12, 2012, 5:37:10 AM4/12/12
to Eli Zaretskii, help-gn...@gnu.org

Here is what works for me on Win7

;; Cygwin for find/grep
(setenv "PATH" (concat "C:\\cygwin\\bin;" (getenv "PATH")))

in .emacs

1. GNU Emacs 24.0.94.1 (i386-mingw-nt6.1.7601)
2. CygWin in C:\cygwin some pretty outdated version

It's dog slow though :(

HTH,
Ev


Eli Zaretskii <el...@gnu.org> writes:

>> From: Steinar Bang <s...@dod.no>
>> Date: Thu, 12 Apr 2012 11:21:41 +0200
>>
>> Platform: emacs 23.2.1,
>> GnuWin32 FindUtils 4.2.20-2
>> GnuWin32 Grep-2.5.4
>
> What version of Windows is that?
>
>> Does anyone know of a way to make the emacs rgrep command work on
>> windows?
>
> First, try Emacs 23.3 or later, there were some changes made there to
> fix problems with very long command lines, perhaps you are hitting
> that limit. If that doesn't help, maybe advice below will.
>
> "M-x rgrep" works for me on Windows XP, but I use Fiindutils that I
> built myself, as the GnuWin32 provided port is broken (in particular,
> xargs is affected). You can find my port here:
>
> http://sourceforge.net/projects/ezwinports/files/
>
> However, lately someone told me that my build doesn't work well on
> Windows Vista and later, because Microsoft changed the way quoted
> wildcards are processed by the startup code that globs them: now
> wildcards are globbed even if they are quoted. If you are using such
> a new version of Windows, the only solution I know of is to downgrade
> to an even older version 4.1 of Findutils from here:
>
> http://unxutils.sourceforge.net/
>
> I think someone told me that this port does work on newer Windows
> versions.
>
> HTH

Steinar Bang

unread,
Apr 13, 2012, 7:34:09 AM4/13/12
to help-gn...@gnu.org
>>>>> Steinar Bang <s...@dod.no>:
>>>>> Eli Zaretskii <el...@gnu.org>:

>> First, try Emacs 23.3 or later, there were some changes made there to
>> fix problems with very long command lines, perhaps you are hitting
>> that limit.

> Thanks! Will try!

Tried emacs 23.4 which was the newest 23.x available. That got me a bit
further:

C:\ProgramFiles\GnuWin32\bin\find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "*/{arch}" ")" -prune -o "(" -name ".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak" -o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o -name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name "*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name "*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name "*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name "*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name "*.x86f" -o -name "*.sparcf" -o -name "*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name "*.pfsl" -o -name "*.dfsl" -o -name "*.p64fsl" -o -name "*.d64fsl" -o -name "*.dx64fsl" -o -name "*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name "*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name "*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o -type f "(" -iname "*.csproj" ")" -print0 | "xargs" -0 -e grep -i -nH -e "searchterm"
'"xargs"' is not recognized as an internal or external command,
operable program or batch file.

In my .emacs I had the following:
;; Make rgrep find the find program from GnuWin32
(setq find-program "C:\\ProgramFiles\\GnuWin32\\bin\\find")

So I looked in grep.el (which defines the find-program variable) and
found that it had an xargs-program variable as well. Defined it like
this in .emacs (note that it is necessary to start a new emacs for the
changes to take effect. Just evaluating that setq in the *scratch*
buffer won't work):
;; Make rgrep find the xargs program from GnuWin32
(setq xargs-program "C:\\ProgramFiles\\GnuWin32\\bin\\xargs")

This worked better, but I got a more or less expected error message that
it couldn't find "grep":

C:\ProgramFiles\GnuWin32\bin\find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "*/{arch}" ")" -prune -o "(" -name ".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak" -o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o -name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name "*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name "*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name "*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name "*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name "*.x86f" -o -name "*.sparcf" -o -name "*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name "*.pfsl" -o -name "*.dfsl" -o -name "*.p64fsl" -o -name "*.d64fsl" -o -name "*.dx64fsl" -o -name "*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name "*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name "*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o -type f "(" -iname "*.csproj" ")" -print0 | "C:\ProgramFiles\GnuWin32\bin\xargs" -0 -e grep -i -nH -e "searchterm"
C:\ProgramFiles\GnuWin32\bin\xargs: grep: No such file or directory

So I added the following to .emacs, and started a fresh emacs 23.4
instance:
;; Make rgrep find the grep program from GnuWin32
(setq grep-program "C:\\ProgramFiles\\GnuWin32\\bin\\grep")

Success!

So in summary:
- Use emacs 23.4
- Install FindUtils and grep from GnuWin32 http://gnuwin32.sourceforge.net/
- Set variables in .emacs to whereever you installed the GnuWin32
binaries:
;; Make rgrep find the GnuWin32 executables it needs
(setq find-program "C:\\ProgramFiles\\GnuWin32\\bin\\find")
(setq xargs-program "C:\\ProgramFiles\\GnuWin32\\bin\\xargs")
(setq grep-program "C:\\ProgramFiles\\GnuWin32\\bin\\grep")

(The use "C:\ProgramFiles" for the GnuWin32 location, is just an old
habit of mine, to give ported unix programs an installation path with no
spaces)

Eli Zaretskii

unread,
Apr 13, 2012, 8:12:34 AM4/13/12
to help-gn...@gnu.org
> From: Steinar Bang <s...@dod.no>
> Date: Fri, 13 Apr 2012 13:34:09 +0200
>
> So in summary:
> - Use emacs 23.4
> - Install FindUtils and grep from GnuWin32 http://gnuwin32.sourceforge.net/
> - Set variables in .emacs to whereever you installed the GnuWin32
> binaries:
> ;; Make rgrep find the GnuWin32 executables it needs
> (setq find-program "C:\\ProgramFiles\\GnuWin32\\bin\\find")
> (setq xargs-program "C:\\ProgramFiles\\GnuWin32\\bin\\xargs")
> (setq grep-program "C:\\ProgramFiles\\GnuWin32\\bin\\grep")

You will be much better off, including with other ports of GNU/Unix
software, if you just put them all on PATH. I see no good reason for
keeping them in a directory that is not on PATH. Not every program
called by Emacs has a user option that allows you to spell out its
full absolute file name.

(FWIW, I have a single `bin' directory into which I put _all_ the
programs and DLLs that do not come with Windows out of the box, and
that directory is very near the beginning of PATH. I have yet to see
a single use case where this arrangement failed me, be it in Emacs or
elsewhere. So this is what I recommend to others, unless there are
_very_ good reasons not to use this setup.)

Evgeniy Dolzhenko

unread,
Apr 13, 2012, 9:02:32 AM4/13/12
to help-gn...@gnu.org
Since my comment about this setup being dog slow went unnoticed I'd like
to reiterate find+xargs+grep are really slow on Windows on just
moderately large projects, so I'm looking for a solution to this? Is it
switching to ack?

Maybe somebody will post an example config for recent Emacs/ack versions?

Cheers,
Ev

Eli Zaretskii

unread,
Apr 13, 2012, 1:42:34 PM4/13/12
to help-gn...@gnu.org
> Date: Fri, 13 Apr 2012 17:02:32 +0400
> From: Evgeniy Dolzhenko <dolz...@gmail.com>
>
> Since my comment about this setup being dog slow went unnoticed I'd like
> to reiterate find+xargs+grep are really slow on Windows on just
> moderately large projects

It is only slow if you use the GnuWin32 port of GNU Find. (They used
a version of `readdir' which traded a marginal feature for abysmally
slow performance.) That was the original reason why I made my own
port, which is between 4 and 10 times faster. Give it a try.

Steinar Bang

unread,
Apr 14, 2012, 4:03:26 AM4/14/12
to help-gn...@gnu.org
>>>>> Eli Zaretskii <el...@gnu.org>:

> You will be much better off, including with other ports of GNU/Unix
> software, if you just put them all on PATH. I see no good reason for
> keeping them in a directory that is not on PATH.

The cmd.exe on my development box have their own utilities with the same
names and different argument, and I don't want to confuse other
utilities in my development environment (which I don't control myself).
Things might stop building because I want rgrep in Gnus.

> Not every program called by Emacs has a user option that allows you to
> spell out its full absolute file name.

I know. I was very happy to find out that grep.el did.

> (FWIW, I have a single `bin' directory into which I put _all_ the
> programs and DLLs that do not come with Windows out of the box, and
> that directory is very near the beginning of PATH. I have yet to see
> a single use case where this arrangement failed me, be it in Emacs or
> elsewhere. So this is what I recommend to others, unless there are
> _very_ good reasons not to use this setup.)

Yes. It's what I would do on a box completely under my control.


Eli Zaretskii

unread,
Apr 14, 2012, 5:04:46 AM4/14/12
to help-gn...@gnu.org
> From: Steinar Bang <s...@dod.no>
> Date: Sat, 14 Apr 2012 10:03:26 +0200
>
> >>>>> Eli Zaretskii <el...@gnu.org>:
>
> > You will be much better off, including with other ports of GNU/Unix
> > software, if you just put them all on PATH. I see no good reason for
> > keeping them in a directory that is not on PATH.
>
> The cmd.exe on my development box have their own utilities with the same
> names and different argument, and I don't want to confuse other
> utilities in my development environment (which I don't control myself).
> Things might stop building because I want rgrep in Gnus.

There's more than one way of cutting this cake.

You could create a special batch file that modifies PATH before it
runs Emacs. You can then make the desktop shortcut which runs Emacs
run that batch file instead. Or you could invoke the batch file
manually from a command shell before running Emacs from that shell.
You can even have a separate shortcut for starting a special-purpose
cmd.exe window, which starts by running that batch file (via the "cmd
/k foo.bat" feature).

I think one of these methods could fit your workflow without adversely
affecting those other utilities.

Ludwig, Mark

unread,
Apr 16, 2012, 9:26:07 AM4/16/12
to Eli Zaretskii, help-gn...@gnu.org
> From: Eli Zaretskii
> Sent: Saturday, April 14, 2012 4:05 AM
> To: help-gn...@gnu.org
> Subject: Re: Is it possible to run rgrep in emacs on Win32?
I suppose my situation is different, but am I the only person who uses the Windows-native FINDSTR utility?

(require 'compile)
(setq grep-command "findstr /n ")

The syntax is of course completely different, and there are certainly significant RegExp differences, but it ignores the "NUL" that appears at the end of the command so basically works and its syntax is similar-enough to grep's that I can mostly forget which one I'm using. (I'm a programmer, so generally am searching for a single word such as a function name....)

I just add the /S option when I want recursive descent behavior....

Cheers,
Mark


winterTTr

unread,
Apr 17, 2012, 1:47:32 AM4/17/12
to help-gn...@gnu.org
I suggest to not use the xargs style. Currently, I almost cannot find a good "find.exe" and "xrags.exe" to work well together.

What I currently used is, using the binary folder comes from msysgit, which should be the find.exe and grep.exe from msys sub system.

At the same time, do not use xargs style for rgrep.

(require 'grep)
(grep-apply-setting
'grep-find-use-xargs 'exec)

use 'exec style, which you can get more information from grep-find-use-xargs documentation.

The currently problem is, this kind of combination is very slow if you use it to find deep directory tree. However, it at least can use without any problem.

winterTTr

unread,
Apr 17, 2012, 1:47:32 AM4/17/12
to gnu.ema...@googlegroups.com, help-gn...@gnu.org
On Thursday, April 12, 2012 5:21:41 PM UTC+8, Steinar Bang wrote:
0 new messages