emacs-diffs
[Top][All Lists]
Advanced

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

master cea0681: Add a new grep-match-regexp variable


From: Lars Ingebrigtsen
Subject: master cea0681: Add a new grep-match-regexp variable
Date: Sun, 27 Sep 2020 08:55:37 -0400 (EDT)

branch: master
commit cea06818a1e7462090df90d41d5298b975ee9b27
Author: Simon Lang <Simon.lang@outlook.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add a new grep-match-regexp variable
    
    * doc/emacs/building.texi (Grep Searching): Document it.
    
    * lisp/progmodes/grep.el (grep-match-regexp): New variable (bug#41766).
    (grep-filter): Use it.
---
 doc/emacs/building.texi | 5 +++++
 etc/NEWS                | 9 +++++++++
 lisp/progmodes/grep.el  | 9 ++++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 7074bd4..5199724 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -427,11 +427,16 @@ M-n}}, @key{RET}, and so forth, just like compilation 
errors.
 @xref{Compilation Mode}, for detailed description of commands and key
 bindings available in the @file{*grep*} buffer.
 
+@vindex grep-match-regexp}
   Some grep programs accept a @samp{--color} option to output special
 markers around matches for the purpose of highlighting.  You can make
 use of this feature by setting @code{grep-highlight-matches} to
 @code{t}.  When displaying a match in the source buffer, the exact
 match will be highlighted, instead of the entire source line.
+Highlighting is provided via matching the @acronym{ANSI} escape
+sequences emitted by @command{grep}.  The matching of the sequences is
+controlled by @code{grep-match-regexp}, which can be customized to
+accommodate different @command{grep} programs.
 
   As with compilation commands (@pxref{Compilation}), while the grep
 command runs, the mode line shows the running number of matches found
diff --git a/etc/NEWS b/etc/NEWS
index 202cd68..61618af 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -518,6 +518,15 @@ take the actual screenshot, and defaults to "ImageMagick 
import".
 A server entry retrieved by auth-source can request a desired smtp
 authentication mechanism by setting a value for the key 'smtp-auth'.
 
+** Grep
+
++++
+*** New variable 'grep-match-regexp' matches grep markers to highlight.
+grep emits SGR ANSI escape sequences to color its output.  The new variable
+'grep-match-regexp' holds the regular expression to match the appropriate
+markers in order to provide highlighting in the source buffer.  The variable
+can be customized to accommodate other grep-like tools.
+
 ** Help
 
 +++
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index c71a903..279eb4d 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -100,6 +100,13 @@ To change the default value, use \\[customize] or call the 
function
   :set #'grep-apply-setting
   :version "22.1")
 
+(defcustom grep-match-regexp "\033\\[0?1;31m\\(.*?\\)\033\\[[0-9]*m"
+  "Regular expression matching grep markers to highlight.
+It matches SGR ANSI escape sequences which are emitted by grep to
+color its output.  This variable is used in `grep-filter'."
+  :type 'regexp
+  :version "28.1")
+
 (defcustom grep-scroll-output nil
   "Non-nil to scroll the *grep* buffer window as output appears.
 
@@ -590,7 +597,7 @@ This function is called from `compilation-filter-hook'."
       (when (< (point) end)
         (setq end (copy-marker end))
         ;; Highlight grep matches and delete marking sequences.
-        (while (re-search-forward "\033\\[0?1;31m\\(.*?\\)\033\\[[0-9]*m" end 
1)
+        (while (re-search-forward grep-match-regexp end 1)
           (replace-match (propertize (match-string 1)
                                      'face nil 'font-lock-face grep-match-face)
                          t t)



reply via email to

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