]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/grep.el
Update copyright year to 2015
[gnu-emacs] / lisp / progmodes / grep.el
index d60534074b9ebed2d5743a89e99cffa4aa9d733e..048fa1180a95a46c3b3df3836b77e7f82a9a93ce 100644 (file)
@@ -1,6 +1,7 @@
 ;;; grep.el --- run `grep' and display the results  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1985-1987, 1993-1999, 2001-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1993-1999, 2001-2015 Free Software
+;; Foundation, Inc.
 
 ;; Author: Roland McGrath <roland@gnu.org>
 ;; Maintainer: emacs-devel@gnu.org
@@ -76,11 +77,10 @@ in grep buffers, so if you have globally disabled font-lock-mode,
 you will not get highlighting.
 
 This option sets the environment variable GREP_COLORS to specify
-markers for highlighting and GREP_OPTIONS to add the --color
-option in front of any explicit grep options before starting
-the grep.
+markers for highlighting and adds the --color option in front of
+any explicit grep options before starting the grep.
 
-When this option is `auto', grep uses `--color=auto' to highlight
+When this option is `auto', grep uses `--color' to highlight
 matches only when it outputs to a terminal (when `grep' is the last
 command in the pipe), thus avoiding the use of any potentially-harmful
 escape sequences when standard output goes to a file or pipe.
@@ -96,7 +96,7 @@ To change the default value, use Customize or call the function
   :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
                 (const :tag "Highlight matches with grep markers" t)
                 (const :tag "Use --color=always" always)
-                (const :tag "Use --color=auto" auto)
+                (const :tag "Use --color" auto)
                 (other :tag "Not Set" auto-detect))
   :set 'grep-apply-setting
   :version "22.1"
@@ -344,16 +344,11 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
 ;;;###autoload
 (defconst grep-regexp-alist
   '(
-    ;; Rule to match column numbers is commented out since no known grep
-    ;; produces them
-    ;; ("^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)\\2\\(?:\\([1-9][0-9]*\\)\\(?:-\\([1-9][0-9]*\\)\\)?\\2\\)?"
-    ;;  1 3 (4 . 5))
-    ;; Note that we want to use as tight a regexp as we can to try and
-    ;; handle weird file names (with colons in them) as well as possible.
-    ;; E.g. we use [1-9][0-9]* rather than [0-9]+ so as to accept ":034:"
-    ;; in file names.
-    ("^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)\\2"
-     1 3
+    ;; Use a tight regexp to handle weird file names (with colons
+    ;; in them) as well as possible.  E.g., use [1-9][0-9]* rather
+    ;; than [0-9]+ so as to accept ":034:" in file names.
+    ("^\\(.*?[^/\n]\\):[ \t]*\\([1-9][0-9]*\\)[ \t]*:"
+     1 2
      ;; Calculate column positions (col . end-col) of first grep match on a line
      ((lambda ()
        (when grep-highlight-matches
@@ -466,10 +461,6 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
     ;; `setenv' modifies `process-environment' let-bound in `compilation-start'
     ;; Any TERM except "dumb" allows GNU grep to use `--color=auto'
     (setenv "TERM" "emacs-grep")
-    (setenv "GREP_OPTIONS"
-           (concat (getenv "GREP_OPTIONS")
-                   " --color=" (if (eq grep-highlight-matches 'always)
-                                   "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
@@ -566,10 +557,28 @@ This function is called from `compilation-filter-hook'."
                        (looking-at
                         (concat (regexp-quote hello-file)
                                 ":[0-9]+:English")))))))))
+
+    (when (eq grep-highlight-matches 'auto-detect)
+      (setq grep-highlight-matches
+           (with-temp-buffer
+             (and (grep-probe grep-program '(nil t nil "--help"))
+                  (progn
+                    (goto-char (point-min))
+                    (search-forward "--color" nil t))
+                  ;; Windows and DOS pipes fail `isatty' detection in Grep.
+                  (if (memq system-type '(windows-nt ms-dos))
+                      'always 'auto)))))
+
     (unless (and grep-command grep-find-command
                 grep-template grep-find-template)
       (let ((grep-options
-            (concat (if grep-use-null-device "-n" "-nH")
+            (concat (and grep-highlight-matches
+                         (grep-probe grep-program
+                                     `(nil nil nil "--color" "x" ,null-device)
+                                     nil 1)
+                         (if (eq grep-highlight-matches 'always)
+                             "--color=always " "--color "))
+                    (if grep-use-null-device "-n" "-nH")
                     (if (grep-probe grep-program
                                     `(nil nil nil "-e" "foo" ,null-device)
                                     nil 1)
@@ -636,16 +645,6 @@ This function is called from `compilation-filter-hook'."
                        (t
                         (format "%s . <X> -type f <F> -print | \"%s\" %s"
                                 find-program xargs-program gcmd))))))))
-    (when (eq grep-highlight-matches 'auto-detect)
-      (setq grep-highlight-matches
-           (with-temp-buffer
-             (and (grep-probe grep-program '(nil t nil "--help"))
-                  (progn
-                    (goto-char (point-min))
-                    (search-forward "--color" nil t))
-                  ;; Windows and DOS pipes fail `isatty' detection in Grep.
-                  (if (memq system-type '(windows-nt ms-dos))
-                      'always 'auto)))))
 
     ;; Save defaults for this host.
     (setq grep-host-defaults-alist