From: Lars Ingebrigtsen <larsi@gnus.org>
To: Juri Linkov <juri@jurta.org>
Cc: Lennart Borgman <lennart.borgman@gmail.com>, 6227@debbugs.gnu.org
Subject: bug#6227: Color isearch regexp submatches differently
Date: Sat, 19 Sep 2020 23:29:48 +0200 [thread overview]
Message-ID: <87mu1llak3.fsf@gnus.org> (raw)
In-Reply-To: <87hbla4nl4.fsf@mail.jurta.org> (Juri Linkov's message of "Thu, 10 Jun 2010 23:52:39 +0300")
Juri Linkov <juri@jurta.org> writes:
>>> I agree, your approach is probably better. But check for more
>>> submatches. Maybe upto the value of some variable, say
>>> isearch-max-submatch-num.
>>
>> Good idea.
>
> Maybe something like this:
The ten year old patch no longer applied to Emacs 28, so I've respun it.
I think the results are really nice. I guess we should add a few more
faces before applying?
Anybody else got any comments on this?
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 7fb1d8a3ca..56eb443d31 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -269,6 +269,14 @@ search-highlight
"Non-nil means incremental search highlights the current match."
:type 'boolean)
+(defcustom search-highlight-submatches 2
+ "Highlight regexp subexpressions of the current regexp match.
+An integer means highlight regexp subexpressions up to the
+specified maximal number.
+When 0, do not highlight regexp subexpressions."
+ :type 'integer
+ :version "28.1")
+
(defface isearch
'((((class color) (min-colors 88) (background light))
;; The background must not be too dark, for that means
@@ -3654,6 +3662,21 @@ isearch-unread
;; Highlighting
(defvar isearch-overlay nil)
+(defvar isearch-submatches-overlays nil)
+
+(defface isearch-1
+ '((((class color) (min-colors 88) (background light))
+ :background "magenta2" :foreground "lightskyblue1")
+ (((class color) (min-colors 88) (background dark))
+ :background "palevioletred3" :foreground "brown4"))
+ "Used for displaying the first matching subexpression.")
+
+(defface isearch-2
+ '((((class color) (min-colors 88) (background light))
+ :background "magenta1" :foreground "lightskyblue1")
+ (((class color) (min-colors 88) (background dark))
+ :background "palevioletred4" :foreground "brown4"))
+ "Used for displaying the second matching subexpression.")
(defun isearch-highlight (beg end)
(if search-highlight
@@ -3664,11 +3687,28 @@ isearch-highlight
(setq isearch-overlay (make-overlay beg end))
;; 1001 is higher than lazy's 1000 and ediff's 100+
(overlay-put isearch-overlay 'priority 1001)
- (overlay-put isearch-overlay 'face isearch-face))))
+ (overlay-put isearch-overlay 'face isearch-face)))
+ (when (and (integerp search-highlight-submatches)
+ (> search-highlight-submatches 0)
+ isearch-regexp)
+ (mapc 'delete-overlay isearch-submatches-overlays)
+ (setq isearch-submatches-overlays nil)
+ (let ((i 0) ov)
+ (while (<= i search-highlight-submatches)
+ (when (match-beginning i)
+ (setq ov (make-overlay (match-beginning i) (match-end i)))
+ (overlay-put ov 'face (intern-soft (format "isearch-%d" i)))
+ (overlay-put ov 'priority 1002)
+ (push ov isearch-submatches-overlays))
+ (setq i (1+ i))))))
(defun isearch-dehighlight ()
(when isearch-overlay
- (delete-overlay isearch-overlay)))
+ (delete-overlay isearch-overlay))
+ (when search-highlight-submatches
+ (mapc 'delete-overlay isearch-submatches-overlays)
+ (setq isearch-submatches-overlays nil)))
+
\f
;; isearch-lazy-highlight feature
;; by Bob Glickstein <http://www.zanshin.com/~bobg/>
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2020-09-19 21:29 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-20 11:01 bug#6227: Color isearch regexp submatches differently Lennart Borgman
2010-05-20 13:21 ` Drew Adams
2010-05-20 13:28 ` Lennart Borgman
2010-05-20 13:33 ` Drew Adams
2010-05-20 15:02 ` Drew Adams
2010-05-21 0:07 ` Juri Linkov
2010-05-21 1:19 ` Lennart Borgman
2010-05-22 23:44 ` Juri Linkov
2010-05-23 0:51 ` Lennart Borgman
2010-05-23 0:54 ` Juri Linkov
2010-05-23 10:04 ` Lennart Borgman
2010-05-23 16:12 ` Juri Linkov
2010-05-23 16:40 ` Lennart Borgman
2010-06-08 13:37 ` Lennart Borgman
2010-06-09 8:36 ` Juri Linkov
2010-06-09 9:14 ` Lennart Borgman
2010-06-10 15:28 ` Juri Linkov
2010-06-10 15:52 ` Lennart Borgman
2010-06-10 20:52 ` Juri Linkov
2010-06-10 21:41 ` Lennart Borgman
2010-06-11 0:44 ` Stefan Monnier
2010-06-11 8:17 ` Juri Linkov
2020-09-19 21:29 ` Lars Ingebrigtsen [this message]
2020-09-19 22:19 ` Drew Adams
2020-09-20 5:39 ` Eli Zaretskii
2020-09-20 9:41 ` Lars Ingebrigtsen
2020-09-20 9:53 ` Eli Zaretskii
2020-09-20 10:04 ` Lars Ingebrigtsen
2020-09-20 13:47 ` Lars Ingebrigtsen
2020-09-20 14:18 ` Eli Zaretskii
2020-09-20 19:45 ` Lars Ingebrigtsen
2020-09-20 20:25 ` Drew Adams
2020-09-21 2:25 ` Eli Zaretskii
2020-09-21 13:48 ` Lars Ingebrigtsen
2020-09-20 16:41 ` Drew Adams
2020-09-20 16:45 ` Eli Zaretskii
[not found] <<AANLkTikUlBKGt388RPJkU8tM6A_fpMPsTkvo6cbI3D56@mail.gmail.com>
[not found] ` <<87bpca15ja.fsf@mail.jurta.org>
[not found] ` <<AANLkTilV0TlRQRCC7-uAuspGAwTYhMySTbh4dOjKIDM0@mail.gmail.com>
[not found] ` <<87wruv1ohr.fsf@mail.jurta.org>
[not found] ` <<AANLkTimRAHa4K6FlX_952j3s2saDmcXMIbDOYx9xk8Fh@mail.gmail.com>
[not found] ` <<877hmvtn9t.fsf@mail.jurta.org>
[not found] ` <<AANLkTiljPa2oALTtTabtFb3_KHhPB9NNqnKzXZWIh_v4@mail.gmail.com>
[not found] ` <<874ohyppfs.fsf@mail.jurta.org>
[not found] ` <<AANLkTilPUyzW5lCEdQv-WD6_0WdVbDiofmN34UHMVLNA@mail.gmail.com>
[not found] ` <<AANLkTileYK0D0RTKAePLbax_9o9JbgNlpuNXbLBzBssY@mail.gmail.com>
[not found] ` <<8739ww1tjp.fsf@mail.jurta.org>
[not found] ` <<AANLkTilwC3QBYmtzPg3zrDoD44deoBsD5rxxP-dNhxnH@mail.gmail.com>
[not found] ` <<87d3vyaodq.fsf@mail.jurta.org>
[not found] ` <<87hbla4nl4.fsf@mail.jurta.org>
[not found] ` <<87mu1llak3.fsf@gnus.org>
[not found] ` <<83lfh50zxa.fsf@gnu.org>
[not found] ` <<87eemwss3t.fsf@gnus.org>
[not found] ` <<834kns22q2.fsf@gnu.org>
[not found] ` <<87sgbcrcgd.fsf@gnus.org>
[not found] ` <<874knso90e.fsf@gnus.org>
[not found] ` <<83pn6gzg3j.fsf@gnu.org>
[not found] ` <<87363ckza5.fsf@gnus.org>
[not found] ` <<835z87zx16.fsf@gnu.org>
2020-09-21 4:49 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mu1llak3.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=6227@debbugs.gnu.org \
--cc=juri@jurta.org \
--cc=lennart.borgman@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).