]> git.eshelyaron.com Git - emacs.git/commitdiff
More robust auto-detect of grep-highlight-matches (bug#49978)
authorMattias Engdegård <mattiase@acm.org>
Tue, 10 Aug 2021 15:04:34 +0000 (17:04 +0200)
committerMattias Engdegård <mattiase@acm.org>
Tue, 10 Aug 2021 15:13:35 +0000 (17:13 +0200)
* lisp/progmodes/grep.el (grep-compute-defaults):
Don't require "grep --help" to finish with exit status 0 (BSD grep
does not) and check the output in a slightly more robust way.

lisp/progmodes/grep.el

index 8f0a5acf708e0eaa96a01695dfb72ea1d0dc871b..b2a9b3e3206881aabcdccbdcb381e2f8a1821be1 100644 (file)
@@ -696,11 +696,12 @@ The value depends on `grep-command', `grep-template',
     (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.
+              ;; The "grep --help" exit status varies; pay no attention to it.
+              (grep-probe grep-program '(nil t nil "--help"))
+             (goto-char (point-min))
+             (and (let ((case-fold-search nil))
+                     (re-search-forward (rx "--color" (not (in "a-z"))) nil t))
+                  ;; Windows and DOS pipes fail `isatty' detection in Grep.
                   (if (memq system-type '(windows-nt ms-dos))
                       'always 'auto)))))