aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2020-10-01 22:17:40 +0300
committerJuri Linkov2020-10-01 22:17:40 +0300
commit306fcc59dcd7d2a6ec8338dfff520a89d7a9121d (patch)
treedf0b512330d17fabb9c04676b777a829845ec0a7
parentd460677b19299fd43fa3a088895a406f9975a3ee (diff)
downloademacs-306fcc59dcd7d2a6ec8338dfff520a89d7a9121d.tar.gz
emacs-306fcc59dcd7d2a6ec8338dfff520a89d7a9121d.zip
Use new faces isearch-group-odd and isearch-group-even (bug#43702)
* lisp/isearch.el (isearch-group-odd, isearch-group-even): New faces instead of isearch-group-1 .. isearch-group-9. (isearch-highlight): Use new faces.
-rw-r--r--doc/emacs/search.texi9
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/isearch.el98
3 files changed, 20 insertions, 90 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index d44d7bee2ac..d982a9e8787 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -1984,10 +1984,11 @@ the @code{search-highlight-submatches} variable. If this variable's
1984value is @code{nil}, no special highlighting is done, but if the value 1984value is @code{nil}, no special highlighting is done, but if the value
1985is non-@code{nil}, text that matches @samp{\( @dots{} \)} constructs 1985is non-@code{nil}, text that matches @samp{\( @dots{} \)} constructs
1986(a.k.a.@: ``subexpressions'') in the regular expression will be 1986(a.k.a.@: ``subexpressions'') in the regular expression will be
1987highlighted with distinct faces, named @code{isearch-group-@var{n}}. 1987highlighted with distinct faces, named @code{isearch-group-odd}
1988For instance, when searching for @samp{foo-\([0-9]+\)}, the part 1988for the odd group matches, and @code{isearch-group-even}
1989matched by @samp{[0-9]+} will be highlighted with the 1989for the even group matches. For instance, when searching for
1990@code{isearch-group-1} face. 1990@samp{foo-\([0-9]+\)}, the part matched by @samp{[0-9]+} will be
1991highlighted with the @code{isearch-group-odd} face.
1991 1992
1992@cindex lazy highlighting customizations 1993@cindex lazy highlighting customizations
1993@vindex isearch-lazy-highlight 1994@vindex isearch-lazy-highlight
diff --git a/etc/NEWS b/etc/NEWS
index 43a99afafa3..3a176f22af4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1097,8 +1097,9 @@ keystrokes.
1097 1097
1098+++ 1098+++
1099*** Interactive regular expression search now uses faces for sub-groups. 1099*** Interactive regular expression search now uses faces for sub-groups.
1100E.g., 'C-M-s foo-\([0-9]+\)' will now use the 'isearch-group-1' face 1100E.g., 'C-M-s foo-\([0-9]+\)' will now use the 'isearch-group-odd' face
1101on the part of the regexp that matches the sub-expression "[0-9]+". 1101on the part of the regexp that matches the sub-expression "[0-9]+".
1102The even group matches are highlighted with the 'isearch-group-even' face.
1102This is controlled by the 'search-highlight-submatches' user option. 1103This is controlled by the 'search-highlight-submatches' user option.
1103This feature is available only on terminals that have enough colors to 1104This feature is available only on terminals that have enough colors to
1104distinguish between sub-expression highlighting. 1105distinguish between sub-expression highlighting.
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 4e964b325cd..781a8c5a93a 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -271,9 +271,8 @@ are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp'
271 271
272(defcustom search-highlight-submatches t 272(defcustom search-highlight-submatches t
273 "Whether to highlight regexp subexpressions of the current regexp match. 273 "Whether to highlight regexp subexpressions of the current regexp match.
274 274The faces used to do the highlights are named `isearch-group-odd' and
275The faces used to do the highlights are named `isearch-group-1', 275`isearch-group-even'."
276`isearch-group-2', and so on."
277 :type 'boolean 276 :type 'boolean
278 :version "28.1") 277 :version "28.1")
279 278
@@ -3664,97 +3663,26 @@ since they have special meaning in a regexp."
3664(defvar isearch-overlay nil) 3663(defvar isearch-overlay nil)
3665(defvar isearch-submatches-overlays nil) 3664(defvar isearch-submatches-overlays nil)
3666 3665
3667(defface isearch-group-1 3666(defface isearch-group-odd
3668 '((((class color) (min-colors 88) (background light)) 3667 '((((class color) (min-colors 88) (background light))
3669 (:background "#ff00ff" :foreground "lightskyblue1")) 3668 (:background "#ff00ff" :foreground "lightskyblue1"))
3670 (((class color) (min-colors 88) (background dark)) 3669 (((class color) (min-colors 88) (background dark))
3671 (:background "palevioletred3" :foreground "brown4")) 3670 (:background "palevioletred3" :foreground "brown4"))
3672 (t (:inherit isearch))) 3671 (t (:inherit isearch)))
3673 "Face for highlighting Isearch sub-group matches (first sub-group)." 3672 "Face for highlighting Isearch the odd group matches."
3674 :group 'isearch
3675 :version "28.1")
3676
3677(defface isearch-group-2
3678 '((((class color) (min-colors 88) (background light))
3679 (:background "#d000d0" :foreground "lightskyblue1"))
3680 (((class color) (min-colors 88) (background dark))
3681 (:background "#be698f" :foreground "black"))
3682 (t (:inherit isearch)))
3683 "Face for highlighting Isearch sub-group matches (second sub-group)."
3684 :group 'isearch
3685 :version "28.1")
3686
3687(defface isearch-group-3
3688 '((((class color) (min-colors 88) (background light))
3689 (:background "#a000a0" :foreground "lightskyblue1"))
3690 (((class color) (min-colors 88) (background dark))
3691 (:background "#a06080" :foreground "brown4"))
3692 (t (:inherit isearch)))
3693 "Face for highlighting Isearch sub-group matches (third sub-group)."
3694 :group 'isearch 3673 :group 'isearch
3695 :version "28.1") 3674 :version "28.1")
3696 3675
3697(defface isearch-group-4 3676(defface isearch-group-even
3698 '((((class color) (min-colors 88) (background light)) 3677 '((((class color) (min-colors 88) (background light))
3699 (:background "#800080" :foreground "lightskyblue1")) 3678 (:background "#800080" :foreground "lightskyblue1"))
3700 (((class color) (min-colors 88) (background dark)) 3679 (((class color) (min-colors 88) (background dark))
3701 (:background "#905070" :foreground "brown4")) 3680 (:background "#905070" :foreground "brown4"))
3702 (t (:inherit isearch))) 3681 (t (:inherit isearch)))
3703 "Face for highlighting Isearch sub-group matches (fourth sub-group)." 3682 "Face for highlighting Isearch the even group matches."
3704 :group 'isearch
3705 :version "28.1")
3706
3707(defface isearch-group-5
3708 '((((class color) (min-colors 88) (background light))
3709 (:background "#600060" :foreground "lightskyblue1"))
3710 (((class color) (min-colors 88) (background dark))
3711 (:background "#804060" :foreground "black"))
3712 (t (:inherit isearch)))
3713 "Face for highlighting Isearch sub-group matches (fifth sub-group)."
3714 :group 'isearch
3715 :version "28.1")
3716
3717(defface isearch-group-6
3718 '((((class color) (min-colors 88) (background light))
3719 (:background "#500050" :foreground "lightskyblue1"))
3720 (((class color) (min-colors 88) (background dark))
3721 (:background "#703050" :foreground "white"))
3722 (t (:inherit isearch)))
3723 "Face for highlighting Isearch sub-group matches (sixth sub-group)."
3724 :group 'isearch
3725 :version "28.1")
3726
3727(defface isearch-group-7
3728 '((((class color) (min-colors 88) (background light))
3729 (:background "#400040" :foreground "lightskyblue1"))
3730 (((class color) (min-colors 88) (background dark))
3731 (:background "#602050" :foreground "white"))
3732 (t (:inherit isearch)))
3733 "Face for highlighting Isearch sub-group matches (seventh sub-group)."
3734 :group 'isearch
3735 :version "28.1")
3736
3737(defface isearch-group-8
3738 '((((class color) (min-colors 88) (background light))
3739 (:background "#300030" :foreground "lightskyblue1"))
3740 (((class color) (min-colors 88) (background dark))
3741 (:background "#501050" :foreground "white"))
3742 (t (:inherit isearch)))
3743 "Face for highlighting Isearch sub-group matches (eighth sub-group)."
3744 :group 'isearch 3683 :group 'isearch
3745 :version "28.1") 3684 :version "28.1")
3746 3685
3747(defface isearch-group-9
3748 '((((class color) (min-colors 88) (background light))
3749 (:background "#200020" :foreground "lightskyblue1"))
3750 (((class color) (min-colors 88) (background dark))
3751 (:background "#400040" :foreground "white"))
3752 (t (:inherit isearch)))
3753 "Face for highlighting Isearch sub-group matches (ninth sub-group)."
3754 :group 'isearch
3755 :version "28.1")
3756
3757
3758(defun isearch-highlight (beg end) 3686(defun isearch-highlight (beg end)
3759 (if search-highlight 3687 (if search-highlight
3760 (if isearch-overlay 3688 (if isearch-overlay
@@ -3769,14 +3697,14 @@ since they have special meaning in a regexp."
3769 isearch-regexp) 3697 isearch-regexp)
3770 (mapc 'delete-overlay isearch-submatches-overlays) 3698 (mapc 'delete-overlay isearch-submatches-overlays)
3771 (setq isearch-submatches-overlays nil) 3699 (setq isearch-submatches-overlays nil)
3772 (let ((i 0) ov) 3700 (dotimes (i (/ (length (match-data)) 2))
3773 (while (<= i 9) 3701 (unless (zerop i)
3774 (when (match-beginning i) 3702 (let ((ov (make-overlay (match-beginning i) (match-end i))))
3775 (setq ov (make-overlay (match-beginning i) (match-end i))) 3703 (overlay-put ov 'face (if (zerop (mod i 2))
3776 (overlay-put ov 'face (intern-soft (format "isearch-group-%d" i))) 3704 'isearch-group-even
3705 'isearch-group-odd))
3777 (overlay-put ov 'priority 1002) 3706 (overlay-put ov 'priority 1002)
3778 (push ov isearch-submatches-overlays)) 3707 (push ov isearch-submatches-overlays))))))
3779 (setq i (1+ i))))))
3780 3708
3781(defun isearch-dehighlight () 3709(defun isearch-dehighlight ()
3782 (when isearch-overlay 3710 (when isearch-overlay