From: Simon Lang Date: Sun, 27 Sep 2020 12:55:22 +0000 (+0200) Subject: Add a new grep-match-regexp variable X-Git-Tag: emacs-28.0.90~5852 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cea06818a1e7462090df90d41d5298b975ee9b27;p=emacs.git 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. --- diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index 7074bd45d71..5199724e69d 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 202cd689d33..61618af780a 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 c71a90344ff..279eb4d54b1 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)