Subject: bug#2397 closed by Eli Zaretskii <[email-masked]> (Re: bug#2397: 23.0.90; grep no longer highlights the match)

From: [email-masked] (Emacs bug Tracking System)
Date: Sat, 28 Feb 2009 17:50:03 +0000

This is an automatic notification regarding your bug report
which was filed against the emacs package:

#2397: 23.0.90; grep no longer highlights the match

It has been closed by Eli Zaretskii <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Eli Zaretskii <[email-masked]> by
replying to this email.

-- 
2397: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=2397
Emacs Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#2397: 23.0.90; grep no longer highlights the match
From: Eli Zaretskii <[email-masked]>
To: Drew Adams <[email-masked]>, [email-masked]
Cc: [email-masked]
Date: Sat, 28 Feb 2009 19:42:33 +0200

> From: "Drew Adams" <[email-masked]>
> Date: Mon, 23 Feb 2009 16:56:14 -0800
> Cc: [email-masked]
> 
> > >> Could you also try running grep from Bash (not from Emacs)
> > >> with options "--color=always" and "--color=auto" and see whether
> > >> it outputs highlighting sequences for both cases in a standalone
> > >> shell?
> > >
> > > Yes, both produce the highlighting.
> > > It is apparently only in Emacs that --color=auto does not work.
> > 
> > Weird.  Maybe a Windows guru could explain the difference.
> 
> I think it's an Emacs guru that's needed (perhaps with some Windows, Cygwin, or
> GNU bash knowledge).

I think this has nothing to do with either Cygwin or Bash.  Drew,
could you please verify that the same problem happens for you in
"emacs -Q" without loading cygwin-mount.el and setup-cygwin.el?

AFAICT, this problem happens because Emacs on Windows invokes
subsidiary programs through a pipe, and that pipe fails the `isatty'
test in Grep.  So "--color=auto" can never work on MS-Windows when
Grep is invoked by Emacs.

I ``fixed'' this by going back, on DOS/Windows only, to the
"--color=always" way we used before Juri installed his 2007-11-23
changes.  It's true that this will reinstate the original problem with
multiple grep invocations in a pipe (on Windows and DOS only), but I
don't see how can that use-case be solved, and having a single
instance of grep in the command is by far more frequent usage.

Here's the change I installed.  Drew, could you please see if it works
for you as well?

2009-02-28  Eli Zaretskii  <[email-masked]>

	* progmodes/grep.el (grep-process-setup) [windows-nt msdos]: Use
	"--color=always".

Index: lisp/progmodes/grep.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -r1.99 -r1.100
--- lisp/progmodes/grep.el	25 Jan 2009 00:54:53 -0000	1.99
+++ lisp/progmodes/grep.el	28 Feb 2009 17:24:29 -0000	1.100
@@ -407,7 +407,11 @@
     ;; `--color=auto' emits escape sequences on a tty rather than on a pipe,
     ;; thus allowing to use multiple grep filters on the command line
     ;; and to output escape sequences only on the final grep output
-    (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=auto"))
+    (setenv "GREP_OPTIONS"
+	    (concat (getenv "GREP_OPTIONS")
+		    ;; Windows and DOS pipes fail `isatty' detection in Grep.
+		    " --color=" (if (memq system-type '(windows-nt ms-dos))
+				    "always" "auto")))
     ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions
     (setenv "GREP_COLOR" "01;31")
     ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions

Subject: 23.0.90; grep no longer highlights the match
From: "Drew Adams" <[email-masked]>
To: <[email-masked]>
Date: Thu, 19 Feb 2009 15:26:41 -0800

emacs -Q
 
load library cygwin-mount.el, then setup-cygwin.el:
 
http://www.emacswiki.org/emacs/cygwin-mount.el
http://www.emacswiki.org/emacs/setup-cygwin.el
 
M-x grep -nH -e pattern *.el
 
The text matching "pattern" is not highlighted. In Emacs 22 it is
highlighted using face `match' (yellow background).

In GNU Emacs 23.0.90.1 (i386-mingw-nt5.1.2600)
 of 2009-02-01 on SOFT-MJASON
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4)'