mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-05 11:45:45 +00:00
Add more isearch submatch faces
* doc/emacs/search.texi (Search Customizations): Adjust documentation. * lisp/isearch.el (search-highlight-submatches): Be a boolean. (isearch-group-{6-9}): New faces. (isearch-highlight): Use the variable as a boolean.
This commit is contained in:
parent
ebad35e4d9
commit
d2b754ec1a
@ -1981,15 +1981,13 @@ setting the variable @code{search-highlight} to @code{nil}.
|
||||
When searching for regular expressions (with @kbd{C-M-s}, for
|
||||
instance), subexpressions receive special highlighting depending on
|
||||
the @code{search-highlight-submatches} variable. If this variable's
|
||||
value is zero, no special highlighting is done, but if the value is a
|
||||
positive integer @var{n}, the strings matching the first @var{n}
|
||||
@samp{\( @dots{} \)} constructs (a.k.a.@: ``subexpressions'') in the
|
||||
regular expression will be highlighted with distinct faces, named
|
||||
@code{isearch-group-@var{n}}. For instance, when searching for
|
||||
@samp{foo-\([0-9]+\)}, the part matched by @samp{[0-9]+} will be
|
||||
highlighted with the @code{isearch-group-1} face if
|
||||
@code{search-highlight-submatches} is greater or equal to 1. The
|
||||
default value of @code{search-highlight-submatches} is 5.
|
||||
value is @code{nil}, no special highlighting is done, but if the value
|
||||
is non-@code{nil}, text that matches @samp{\( @dots{} \)} constructs
|
||||
(a.k.a.@: ``subexpressions'') in the regular expression will be
|
||||
highlighted with distinct faces, named @code{isearch-group-@var{n}}.
|
||||
For instance, when searching for @samp{foo-\([0-9]+\)}, the part
|
||||
matched by @samp{[0-9]+} will be highlighted with the
|
||||
@code{isearch-group-1} face.
|
||||
|
||||
@cindex lazy highlighting customizations
|
||||
@vindex isearch-lazy-highlight
|
||||
|
3
etc/NEWS
3
etc/NEWS
@ -1046,8 +1046,7 @@ window after starting). This variable defaults to nil.
|
||||
*** Interactive regular expression search now uses faces for sub-groups.
|
||||
E.g., 'C-M-s foo-\([0-9]+\)' will now use the 'isearch-group-1' face
|
||||
on the part of the regexp that matches the sub-expression "[0-9]+".
|
||||
This is controlled by the 'search-highlight-submatches' variable,
|
||||
whose default value is 5.
|
||||
This is controlled by the 'search-highlight-submatches' variable.
|
||||
|
||||
---
|
||||
*** New user option 'reveal-auto-hide'.
|
||||
|
@ -269,17 +269,12 @@ are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp'
|
||||
"Non-nil means incremental search highlights the current match."
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom search-highlight-submatches 5
|
||||
(defcustom search-highlight-submatches t
|
||||
"Whether to highlight regexp subexpressions of the current regexp match.
|
||||
A positive integer N means highlight regexp subexpressions 1 to N.
|
||||
|
||||
When 0, do not highlight regexp subexpressions. A negative value is
|
||||
treated as zero.
|
||||
|
||||
The faces used to do the highlights are named `isearch-group-1',
|
||||
`isearch-group-2', and so on, and if you increase this variable from
|
||||
the default, you have to add more of these faces."
|
||||
:type 'integer
|
||||
`isearch-group-2', and so on."
|
||||
:type 'boolean
|
||||
:version "28.1")
|
||||
|
||||
(defface isearch
|
||||
@ -3719,6 +3714,47 @@ since they have special meaning in a regexp."
|
||||
:group 'isearch
|
||||
:version "28.1")
|
||||
|
||||
(defface isearch-group-6
|
||||
'((((class color) (background light))
|
||||
(:background "#500050" :foreground "lightskyblue1"))
|
||||
(((class color) (background dark))
|
||||
(:background "#703050" :foreground "white"))
|
||||
(t (:inverse-video t)))
|
||||
"Face for highlighting Isearch sub-group matches (sixth sub-group)."
|
||||
:group 'isearch
|
||||
:version "28.1")
|
||||
|
||||
(defface isearch-group-7
|
||||
'((((class color) (background light))
|
||||
(:background "#400040" :foreground "lightskyblue1"))
|
||||
(((class color) (background dark))
|
||||
(:background "#602050" :foreground "white"))
|
||||
(t (:inverse-video t)))
|
||||
"Face for highlighting Isearch sub-group matches (seventh sub-group)."
|
||||
:group 'isearch
|
||||
:version "28.1")
|
||||
|
||||
(defface isearch-group-8
|
||||
'((((class color) (background light))
|
||||
(:background "#300030" :foreground "lightskyblue1"))
|
||||
(((class color) (background dark))
|
||||
(:background "#501050" :foreground "white"))
|
||||
(t (:inverse-video t)))
|
||||
"Face for highlighting Isearch sub-group matches (eighth sub-group)."
|
||||
:group 'isearch
|
||||
:version "28.1")
|
||||
|
||||
(defface isearch-group-9
|
||||
'((((class color) (background light))
|
||||
(:background "#200020" :foreground "lightskyblue1"))
|
||||
(((class color) (background dark))
|
||||
(:background "#400040" :foreground "white"))
|
||||
(t (:inverse-video t)))
|
||||
"Face for highlighting Isearch sub-group matches (ninth sub-group)."
|
||||
:group 'isearch
|
||||
:version "28.1")
|
||||
|
||||
|
||||
(defun isearch-highlight (beg end)
|
||||
(if search-highlight
|
||||
(if isearch-overlay
|
||||
@ -3729,13 +3765,12 @@ since they have special meaning in a regexp."
|
||||
;; 1001 is higher than lazy's 1000 and ediff's 100+
|
||||
(overlay-put isearch-overlay 'priority 1001)
|
||||
(overlay-put isearch-overlay 'face isearch-face)))
|
||||
(when (and (integerp search-highlight-submatches)
|
||||
(> search-highlight-submatches 0)
|
||||
(when (and search-highlight-submatches
|
||||
isearch-regexp)
|
||||
(mapc 'delete-overlay isearch-submatches-overlays)
|
||||
(setq isearch-submatches-overlays nil)
|
||||
(let ((i 0) ov)
|
||||
(while (<= i search-highlight-submatches)
|
||||
(while (<= i 9)
|
||||
(when (match-beginning i)
|
||||
(setq ov (make-overlay (match-beginning i) (match-end i)))
|
||||
(overlay-put ov 'face (intern-soft (format "isearch-group-%d" i)))
|
||||
|
Loading…
Reference in New Issue
Block a user