Subject: Re: bug#7785: rgrep is broken on woe32

From: Eli Zaretskii <[email-masked]>
Date: Thu, 06 Jan 2011 11:02:28 -0500

> Date: Thu, 6 Jan 2011 10:17:17 -0500
> From: Sam Steingold <[email-masked]>
> Cc: [email-masked], [email-masked]
> 
> > I suggest to fix PATH outside Emacs instead.  I wrote in bug#7793 why.
> 
> is it safe to prepend gnuwin path before the system windows paths
> globally for all programs?

Yes, in my experience.

> my toolchain is not limited to the gnu world, I am afraid of breaking,
> e.g., ms visual studio...

I have VS installed on one of my machines that I use daily, and I have
yet to see even a single problem.  In general, programs that come with
VS don't include namesakes of GNU tools.

> > Also, you said just a couple of messages ago, that rgrep did work for
> > you in "emacs -q".  So is the only difference between that and this
> > whatever you have on your .emacs?  Or am I missing something else?
> 
> 1. "emacs -Q" started from bash shell:

It looks like now nothing works, is that right?  Then what was this
about:

> this works just fine, like on linux:
> PATH=/cygdrive/c/gnu/gnuwin32/bin:$PATH emacs -q
> 
> moreover,
> emacs -q
> and moving gnuwin dir to the beginning of exec-path with
> (let ((gw "c:/gnu/gnuwin32/bin"))
>   (setq exec-path (cons gw (delete gw exec-path))))
> also works fine.

?  What is different between these 2 "working" instances and what you
tried now?

> (getenv "PATH")
> "C:\\gnu\\cygwin\\usr\\local\\bin;C:\\gnu\\cygwin\\bin;C:\\gnu\\cygwin\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\gnu\\clisp-2.49;C:\\Program
> Files\\TortoiseSVN\\bin;C:\\gnu\\gnuwin32\\bin;C:\\gnu\\cygwin\\bin;D:\\bin;C:\\Program
> Files (x86)\\TortoiseHg\\;C:\\Program Files
> (x86)\\Bazaar;C:\\gnu\\GnuTLS-2.10.1\\bin"
> 
> find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path
> "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" .....
> -exec grep -i -nH "asdf" {} NUL ";"
> 
> grep: NUL: No such file or directory
> grep: NUL: No such file or directory
> grep: NUL: No such file or directory
> grep: NUL: No such file or directory
> grep: NUL: No such file or directory
> 
> i.e., cygwin tools are used, which sucks because of NULs but at least
> things sort of work.

Does this problem go away if you set grep-use-null-device to
"/dev/null"?  You could also customize null-device, if you always use
the Cygwin shell.

> find . "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS"
> -o.....-name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name
> "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o  -type f "("
> -iname "*" -o -iname ".*" ")" -print0 | xargs -0 -e grep -i -nH "sfdg"
> xargs: grep: No such file or directory
> grep: ./src/clisp/current/src/config: No such file or directory
> find: write error: Invalid argument
> 
> i.e., apparently, gnuwin tools are used, but nothing works.

I suspect that the shell picks up xargs from Cygwin or something.
Could you try forcing it to use the GnuWin32 binary, or at least
verifying that a GnuWin32 binaries of all the 3 programs get invoked?

> 4. emacs started from desktop with my full huge .emacs but without PATH tweaking
> 
> (getenv "PATH")
> "C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\gnu\\clisp-2.49;C:\\Program
> Files\\TortoiseSVN\\bin;c:\\gnu\\gnuwin32\\bin;c:\\gnu\\cygwin\\bin;d:\\bin;C:\\Program
> Files (x86)\\TortoiseHg\\;C:\\Program Files
> (x86)\\Bazaar;C:\\gnu\\GnuTLS-2.10.1\\bin"
> 
> c:/gnu/gnuwin32/bin/find . \( -path  -o -path \*/attic ..... -o -iname
> Makefile\* -o -iname \*.xml \) -print0 | c:/gnu/gnuwin32/bin/xargs -0
> -e c:/gnu/gnuwin32/bin/grep -i -nH sadf
> 'c:' is not recognized as an internal or external command,
> operable program or batch file.

This is because "c:/gnu/gnuwin32/bin/xargs", which is after the pipe
symbol, is not quoted.  So this is something I do understand.

> 5. same as 4 but without setting find-program et al
> FIND: Parameter format not correct

Also, understood: it picks find.exe from C:/WINDOWS/system32, which is
first on PATH.

> 6. emacs started from desktop with my full huge .emacs with PATH
> tweaking without setting find-program et al:
> 
> (getenv "PATH")
> "c:\\gnu\\gnuwin32\\bin;c:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\gnu\\clisp-2.49;C:\\Program
> Files\\TortoiseSVN\\bin;c:\\gnu\\cygwin\\bin;d:\\bin;C:\\Program Files
> (x86)\\TortoiseHg\\;C:\\Program Files
> (x86)\\Bazaar;C:\\gnu\\GnuTLS-2.10.1\\bin;c:\\sds\\src\\emacs\\trunk\\bin"
> 
> find . \( -path  -o -path \*/attic -o -path .....-iname \*.in -o
> -iname Makefile\* -o -iname \*.xml \) -print0 | xargs -0 -e grep -i
> -nH asdf
> find: paths must precede expression
> Usage: find [-H] [-L] [-P] [path...] [expression]

This somehow uses the wrong quoting style.  Can you look into
shell-quote-argument and see why?

> 7. emacs -Q started from desktop:
> 
> (getenv "PATH")
> "C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\gnu\\clisp-2.49;C:\\Program
> Files\\TortoiseSVN\\bin;c:\\gnu\\gnuwin32\\bin;c:\\gnu\\cygwin\\bin;d:\\bin;C:\\Program
> Files (x86)\\TortoiseHg\\;C:\\Program Files
> (x86)\\Bazaar;C:\\gnu\\GnuTLS-2.10.1\\bin"
> 
> find . "(" -path "*/SCCS" ... -name "*.pyc" -o -name "*.pyo" ")"
> -prune -o  -type f "(" -iname "*" -o -iname ".*" ")" -exec grep -i -nH
> "rg	" {} NUL ";"
> FIND: Parameter format not correct

Again, the MS find.exe, because of PATH.