From: Mattias EngdegÄrd Date: Tue, 10 Aug 2021 15:04:34 +0000 (+0200) Subject: More robust auto-detect of grep-highlight-matches (bug#49978) X-Git-Tag: emacs-28.0.90~1567 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d858a637c2ef35079fbc6cd8b2674c6b13de1e99;p=emacs.git More robust auto-detect of grep-highlight-matches (bug#49978) * 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. --- diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 8f0a5acf708..b2a9b3e3206 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -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)))))