From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#6227: Color isearch regexp submatches differently Date: Thu, 10 Jun 2010 23:52:39 +0300 Organization: JURTA Message-ID: <87hbla4nl4.fsf@mail.jurta.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> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1276203524 31754 80.91.229.12 (10 Jun 2010 20:58:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 Jun 2010 20:58:44 +0000 (UTC) Cc: 6227@debbugs.gnu.org To: Lennart Borgman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 10 22:58:40 2010 connect(): No such file or directory Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OMopg-0003u6-1E for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Jun 2010 22:58:36 +0200 Original-Received: from localhost ([127.0.0.1]:40703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMope-0003xu-S5 for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Jun 2010 16:58:35 -0400 Original-Received: from [140.186.70.92] (port=38100 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMopT-0003w5-6Q for bug-gnu-emacs@gnu.org; Thu, 10 Jun 2010 16:58:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMopR-0006R4-R3 for bug-gnu-emacs@gnu.org; Thu, 10 Jun 2010 16:58:23 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55622) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMopR-0006Qz-PV for bug-gnu-emacs@gnu.org; Thu, 10 Jun 2010 16:58:21 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OMomE-0006gf-8K; Thu, 10 Jun 2010 16:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 10 Jun 2010 20:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6227 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6227-submit@debbugs.gnu.org id=B6227.127620325425693 (code B ref 6227); Thu, 10 Jun 2010 20:55:02 +0000 Original-Received: (at 6227) by debbugs.gnu.org; 10 Jun 2010 20:54:14 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMolS-0006gM-2g for submit@debbugs.gnu.org; Thu, 10 Jun 2010 16:54:14 -0400 Original-Received: from smtp-out1.starman.ee ([85.253.0.3] helo=mx1.starman.ee) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMolP-0006gE-LA for 6227@debbugs.gnu.org; Thu, 10 Jun 2010 16:54:12 -0400 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (82.131.99.15.cable.starman.ee [82.131.99.15]) by mx1.starman.ee (Postfix) with ESMTP id 0DCE73F40BA; Thu, 10 Jun 2010 23:53:57 +0300 (EEST) In-Reply-To: <87d3vyaodq.fsf@mail.jurta.org> (Juri Linkov's message of "Thu, 10 Jun 2010 18:28:57 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 10 Jun 2010 16:55:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:37680 Archived-At: >> 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: === modified file 'lisp/isearch.el' --- lisp/isearch.el 2010-06-10 14:32:41 +0000 +++ lisp/isearch.el 2010-06-10 20:51:43 +0000 @@ -223,6 +223,15 @@ (defcustom search-highlight t :type 'boolean :group 'isearch) +(defcustom search-highlight-submatches 0 + "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 "24.1" + :group 'isearch) + (defface isearch '((((class color) (min-colors 88) (background light)) ;; The background must not be too dark, for that means @@ -2526,6 +2535,23 @@ (defun isearch-unread (&rest char-or-eve ;; 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." + :group 'isearch) + +(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." + :group 'isearch) (defun isearch-highlight (beg end) (if search-highlight @@ -2536,11 +2562,28 @@ (defun isearch-highlight (beg end) (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)))) + (overlay-put isearch-overlay 'face isearch))) + (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 -- Juri Linkov http://www.jurta.org/emacs/