all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <2397@emacsbugs.donarmstrong.com>, <emacs-pretest-bug@gnu.org>
Subject: bug#2397: 23.0.90; grep no longer highlights the match
Date: Sun, 22 Feb 2009 09:56:52 -0800	[thread overview]
Message-ID: <000f01c99516$f20a9a10$0200a8c0@us.oracle.com> (raw)
In-Reply-To: <011f01c992e9$854a3cc0$c2b22382@us.oracle.com>

The bug seems to have been introduced here:

Revision 1.81 - (view) (download) (annotate) - [select for diffs] 
Fri Nov 23 00:32:05 2007 UTC (15 months ago) by jurta 
Branch: MAIN 
Changes since 1.80: +9 -4 lines 
Diff to previous 1.80 
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Set envvar "GREP_OPTIONS" to "--color=auto" instead of "--color=always".

That change seems to have removed the pattern highlighting, by changing this:

(defun grep-process-setup ()
  "Setup compilation variables and buffer for `grep'.
Set up `compilation-exit-message-function' and run `grep-setup-hook'."
  (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
    (grep-compute-defaults))
  (when (eq grep-highlight-matches t)
    ;; Modify `process-environment' locally bound in `compilation-start'
    (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
    ;; for GNU grep 2.5.1
    (setenv "GREP_COLOR" "01;31")
    ;; for GNU grep 2.5.1-cvs
    (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:ml=:cx=:ne"))
  (set (make-local-variable 'compilation-exit-message-function)
       (lambda (status code msg)
	 (if (eq status 'exit)
	     (cond ((zerop code)
		    '("finished (matches found)\n" . "matched"))
		   ((= code 1)
		    '("finished with no matches found\n" . "no match"))
		   (t
		    (cons msg code)))
	   (cons msg code))))
  (run-hooks 'grep-setup-hook))

To this:

(defun grep-process-setup ()
  "Setup compilation variables and buffer for `grep'.
Set up `compilation-exit-message-function' and run `grep-setup-hook'."
  (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
    (grep-compute-defaults))
  (when (eq grep-highlight-matches t)
    ;; `setenv' modifies `process-environment' let-bound in `compilation-start'
    ;; Any TERM except "dumb" allows GNU grep to use `--color=auto'
    (setenv "TERM" "emacs-grep")
    ;; `--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"))
    ;; 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
    (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:ml=:cx=:ne"))
  (set (make-local-variable 'compilation-exit-message-function)
       (lambda (status code msg)
	 (if (eq status 'exit)
	     (cond ((zerop code)
		    '("finished (matches found)\n" . "matched"))
		   ((= code 1)
		    '("finished with no matches found\n" . "no match"))
		   (t
		    (cons msg code)))
	   (cons msg code))))
  (run-hooks 'grep-setup-hook))

Eval'ing the former is enough to restore the pattern highlighting.

Even more specifically, it is the change from 
(setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
to
(setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=auto"))
that introduces the bug. Putting back `always' in place of `auto' restores the
highlighting.

Why `auto' doesn't work, I don't know. 

Again, I have Cygwin on MS Windows, and my shell is bash. I don't know how to
determine my Cygwin version, but it seems to date from 2007-08-22. In any case,
Emacs should work with older versions of Cygwin also, and the version I have
does support highlighting, if `--color=always' is used. 

`man grep' shows this for me, which seems to indicate that `auto' is also
supported, but it doesn't say what `auto' means/does(!):

--colour[=WHEN], --color[=WHEN]
 Surround the matching string with the marker find in GREP_COLOR
 environment variable. WHEN may be `never', `always', or `auto'

GREP_OPTIONS
 This variable specifies default options to be placed in front of
 any  explicit  options.   For  example,   if   GREP_OPTIONS   is
 '--binary-files=without-match  --directories=skip', grep behaves
 as if the two options --binary-files=without-match and  --direc-
 tories=skip  had  been  specified  before  any explicit options.
 Option specifications are separated by whitespace.  A  backslash
 escapes  the  next  character,  so  it can be used to specify an
 option containing whitespace or a backslash.

GREP_COLOR
 Specifies the marker for highlighting.







  reply	other threads:[~2009-02-22 17:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <utz6eo3ue.fsf@gnu.org>
2009-02-19 23:26 ` bug#2397: 23.0.90; grep no longer highlights the match Drew Adams
2009-02-22 17:56   ` Drew Adams [this message]
2009-02-22 19:01     ` Juri Linkov
2009-02-22 20:04       ` Drew Adams
2009-02-22 22:08         ` Juri Linkov
2009-02-22 22:27           ` Drew Adams
2009-02-22 22:52             ` Juri Linkov
2009-02-22 23:14               ` Drew Adams
2009-02-22 23:48                 ` Juri Linkov
2009-02-24  0:56                   ` Drew Adams
2009-02-28 17:50   ` bug#2397: marked as done (23.0.90; grep no longer highlights the match) Emacs bug Tracking System
     [not found] ` <000701c999ce$aa77cb20$0200a8c0@us.oracle.com>
     [not found]   ` <usklyo063.fsf@gnu.org>
     [not found]     ` <001201c999da$77282650$0200a8c0@us.oracle.com>
2009-02-28 20:10       ` bug#2397: 23.0.90; grep no longer highlights the match Eli Zaretskii
2009-02-28 21:09         ` Drew Adams
2009-02-28 22:08           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000f01c99516$f20a9a10$0200a8c0@us.oracle.com' \
    --to=drew.adams@oracle.com \
    --cc=2397@emacsbugs.donarmstrong.com \
    --cc=emacs-pretest-bug@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.