bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#2397: 23.0.90; grep no longer highlights the match


From: Drew Adams
Subject: bug#2397: 23.0.90; grep no longer highlights the match
Date: Sun, 22 Feb 2009 09:56:52 -0800

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 via email to

[Prev in Thread] Current Thread [Next in Thread]