Emacs grep Problem in Windows
Perm url with updates: http://xahlee.org/emacs/emacs_grep_problem.html
Emacs grep Problem in Windows
Xah Lee, 2011-04-05
2 month ago i wrote How to Write grep in Emacs Lisp. In it, i documented a few problems of calling unix grep within emacs. Today i run into a problem again. Here's a more concrete example.
In my vocabulary page Wordy English — the Making of Belles-Lettres, i use the unicode BOX DRAWINGS LIGHT VERTICAL “│” as a temp marker for processing the word list. Today i need to grep pages containing that character.
Calling 【M-x grep】 in emacs with
grep -inH -e "│" *html returns a error:
-*- mode: grep; default-directory: "c:/Users/xah/web/xahlee_org/emacs/" -*- Grep started at Tue Apr 05 15:37:47 grep "│" *html warning: extra args ignored after 'grep "│\' Grep finished with no matches found at Tue Apr 05 15:37:47
Starting “shell” in emacs (which runs Microsoft cmd.exe in Windows Vista) doesn't work neither. (it works fine when grepping ASCII string) Here's a session log:
Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved. c:\Users\xah\web\xahlee_org\emacs>grep "│" *html grep "â? *html
It stuck there. 【C-c C-c】 doesn't get out. I had to kill the buffer.
Calling “msys-shell” works. (msys-shell is bundled with ErgoEmacs. msys-shell is part of MinGW, which is a subset of cygwin port.) Here's a log:
sh-3.2$ grep "│" *html antonymous_synonyms.html:<li> cry, decry │ you can cry, as in crying out loud, but you can also decry, by crying out loud </li> antonymous_synonyms.html:<li> linear, rectilinear │ linear algebra, rectilinear motion. Rectilinear is the linearness of motion.</li> …
Calling it in cygwin bash running inside Windows Console also works.
So, this means, the problem isn't “grep” not understanding unicode. Both cygwin bash grep and msys bash grep works. It must be something that got screwed up when emacs talks to shell. Though, what exactly is the problem? Well, i'm not about to spend few hours to find out.
in PowerShell, it also works. e.g. with this command
select-string -path *.html -pattern "│". However, calling PowerShell thru emacs does not work. (See: Emacs PowerShell Modes.)
So, the problem obviously is the interface between emacs and OS, though, msys does work...
Here's my system setup:
- I'm running ErgoEmacs 1.9.2.
- Windows Vista with latest patches.
- Cygwin installed. (too lazy to lookup version)
- MSYS of MinGW installed as part of ErgoEmacs. (too lazy to lookup version)
- Windows PowerShell installed (too lazy to lookup version)
- PowerShell emacs interface mode installed (too lazy to lookup version)
- PowerShell vs Bash Compared (PowerShell for Unixers)
- Emacs Shell Tutorial (bash, cmd.exe, PowerShell)
- Windows Environment Variables
- Unix Shell Text Processing Tutorial (grep, cat, awk, sort, uniq)
- Unicode Support in File Names: Windows, Mac, Emacs, Unison, Rsync, USB, Zip
- Emacs and Microsoft Windows Tips