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 homep开发者_StackOverflow社区age 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?
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.
Windows doesn't come with a grep
utility (in fact it does have findstr
, but it's not exactly the same), so you need to install something like cygwin or unix utils for windows. After installing those, you need to add them to %PATH%
, so that windows would know where to look for them. You can do that either in command line by running cmd.exe
and issuing a command set PATH=<your_path>;%PATH%
or in some settings widow you get by right clicking a My Computer icon (called something like environment variables here are some pictures of it).
Note, windows has a utility called find
and it is also in system %PATH%
, that can make certain commands (like M-x grep-find
) not work correctly, so it is important you put unix-find first in your %PATH%
.
I think the EmacsW32 user first need to set the user option w32shell-shell
via the menu Options > Customize EmacsW32
, which is set to none originally, and the user should set it to either cmd or cygwin. Setting it to cmd means M-x grep will use the built-in Gnuwin32 grep (and cmd.exe as a shell) and if the setting is saved correctly, the dotemacs will contain lines like the following:
(custom-set-variables
...
'(w32shell-shell (quote cmd))
...)
The custom-set-variable form should be placed as close to the beginning of the dotemacs as possible.
For some reason in my system, this is not enough, M-x grep will insist to use "grep -n" as its template rather than "grep -nH -e" and it always appends "NUL". In that case, add the following line in the dotemacs file.
(grep-compute-defaults)
Here's a no-nonsense answer that works:
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/39cd9d63b07a9988#
Enjoy!
I use Cygwin (an old version). For Emacs I use libraries cygwin-mount.el and setup-cygwin.el, loaded in that order. Works just fine.
精彩评论