From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#6227: Color isearch regexp submatches differently Date: Sat, 19 Sep 2020 23:29:48 +0200 Message-ID: <87mu1llak3.fsf@gnus.org> References: <87bpca15ja.fsf@mail.jurta.org> <87wruv1ohr.fsf@mail.jurta.org> <877hmvtn9t.fsf@mail.jurta.org> <874ohyppfs.fsf@mail.jurta.org> <8739ww1tjp.fsf@mail.jurta.org> <87d3vyaodq.fsf@mail.jurta.org> <87hbla4nl4.fsf@mail.jurta.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38211"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Lennart Borgman , 6227@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 19 23:31:35 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJkSE-0009pJ-GC for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Sep 2020 23:31:34 +0200 Original-Received: from localhost ([::1]:49718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJkSC-0000Lm-Rv for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Sep 2020 17:31:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJkRi-0000LY-Tc for bug-gnu-emacs@gnu.org; Sat, 19 Sep 2020 17:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJkRi-0003Fe-IH for bug-gnu-emacs@gnu.org; Sat, 19 Sep 2020 17:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kJkRi-0004QH-Cr for bug-gnu-emacs@gnu.org; Sat, 19 Sep 2020 17:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Sep 2020 21:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6227 X-GNU-PR-Package: emacs Original-Received: via spool by 6227-submit@debbugs.gnu.org id=B6227.160055100713947 (code B ref 6227); Sat, 19 Sep 2020 21:31:02 +0000 Original-Received: (at 6227) by debbugs.gnu.org; 19 Sep 2020 21:30:07 +0000 Original-Received: from localhost ([127.0.0.1]:48269 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJkQo-0003cs-KK for submit@debbugs.gnu.org; Sat, 19 Sep 2020 17:30:07 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:52334) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJkQm-0003Yc-VU for 6227@debbugs.gnu.org; Sat, 19 Sep 2020 17:30:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xNX5pg9IxJm6yz7/OCBFKPtFiRN5rY42ofeWkQdlKdU=; b=KCC2bqwpNK2HscEp3xW3FcnYvi z/Pe9mFM6/cXEiM3WjFAfttmGTyYS9vrZEuf2J0/HzQIRuNj30+ii8UKS8dJVlFGKJzuJctKeLHRD W7UGKXj7yK/BhaGm72ux6zsW7CC0P5Q5kEmEtnvV17KuCmjHK80G5stNZMl2Eq4zNhYA=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJkQY-0006fx-4N; Sat, 19 Sep 2020 23:29:58 +0200 X-Now-Playing: The Art of Noise's _In No Sense? Nonsense!_: "One Earth" In-Reply-To: <87hbla4nl4.fsf@mail.jurta.org> (Juri Linkov's message of "Thu, 10 Jun 2010 23:52:39 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:188440 Archived-At: Juri Linkov 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))) + ;; isearch-lazy-highlight feature ;; by Bob Glickstein -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no