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.
This commit is contained in:
Simon Lang 2020-09-27 14:55:22 +02:00 committed by Lars Ingebrigtsen
parent 8bd233a7eb
commit cea06818a1
3 changed files with 22 additions and 1 deletions

View file

@ -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

View file

@ -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
+++

View file

@ -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)