all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Helsley <helsleya@cs.ucr.edu>
To: emacs-devel@gnu.org
Subject: [PATCH] isearch: lazy-highlighting of sub-exps of regexps
Date: Mon, 22 Nov 2010 02:38:28 -0800 (PST)	[thread overview]
Message-ID: <alpine.LRH.2.00.1011220044390.17469@eon.cs.ucr.edu> (raw)

[-- Attachment #1: Type: TEXT/PLAIN, Size: 382 bytes --]

Hi,

Attached is a patch for `isearch-mode'.  With this enhancement, the user 
can easily see examples of what the groups in their regular expressions 
capture as they type them.  Using this feedback should make it easier for 
the user to accurately build a replacement string when they invoke 
`query-replace-regexp' directly from `isearch-mode'.

--------
regards,
Andrew Helsley

[-- Attachment #2: Type: TEXT/PLAIN, Size: 4993 bytes --]

diff -r -c emacs-1/lisp/ChangeLog emacs-2/lisp/ChangeLog
*** emacs-1/lisp/ChangeLog	2010-11-22 00:28:12.000000000 -0800
--- emacs-2/lisp/ChangeLog	2010-11-22 00:42:23.000000000 -0800
***************
*** 1,3 ****
--- 1,9 ----
+ 2010-11-22  Andrew Helsley <helsleya@cs.ucr.edu>
+ 
+ 	* isearch.el: Added lazy-highlighting of up to 9 sub-expressions of
+ 	isearch regexps using different faces for each
+ 	(isearch-lazy-highlight-propertize-one-match).
+ 
  2010-11-22  Tassilo Horn  <tassilo@member.fsf.org>
  
  	* textmodes/reftex-ref.el (reftex-goto-label): Use the current
diff -r -c emacs-1/lisp/isearch.el emacs-2/lisp/isearch.el
*** emacs-1/lisp/isearch.el	2010-11-21 22:57:58.000000000 -0800
--- emacs-2/lisp/isearch.el	2010-11-22 00:37:55.000000000 -0800
***************
*** 2581,2586 ****
--- 2581,2590 ----
  (defvar isearch-lazy-highlight-regexp nil)
  (defvar isearch-lazy-highlight-space-regexp nil)
  (defvar isearch-lazy-highlight-forward nil)
+ (defvar isearch-lazy-highlight-last-capture-face 9)
+ (defvar isearch-lazy-highlight-minimum-overlay-priority 1000
+   "Minimum priority to assign to `isearch' mode overlays.
+ 1000 is higher than `ediff's 100+.")
  
  (defun lazy-highlight-cleanup (&optional force)
    "Stop lazy highlighting and remove extra highlighting from current buffer.
***************
*** 2717,2729 ****
  			      (forward-char -1)))
  
  			;; non-zero-length match
! 			(let ((ov (make-overlay mb me)))
! 			  (push ov isearch-lazy-highlight-overlays)
! 			  ;; 1000 is higher than ediff's 100+,
! 			  ;; but lower than isearch main overlay's 1001
! 			  (overlay-put ov 'priority 1000)
! 			  (overlay-put ov 'face lazy-highlight-face)
! 			  (overlay-put ov 'window (selected-window))))
  		      (if isearch-lazy-highlight-forward
  			  (setq isearch-lazy-highlight-end (point))
  			(setq isearch-lazy-highlight-start (point)))))
--- 2721,2727 ----
  			      (forward-char -1)))
  
  			;; non-zero-length match
! 			(isearch-lazy-highlight-propertize-one-match))
  		      (if isearch-lazy-highlight-forward
  			  (setq isearch-lazy-highlight-end (point))
  			(setq isearch-lazy-highlight-start (point)))))
***************
*** 2747,2752 ****
--- 2745,2801 ----
  		    (run-at-time lazy-highlight-interval nil
  				 'isearch-lazy-highlight-update)))))))))
  
+ (defun isearch-lazy-highlight-propertize-one-match ()
+   "Propertize the groups of the most recent regexp match."
+   (let* ((matches   (match-data))
+ 	 (n	    0))
+     (while (>= (length matches) 2)
+       (let* ((m   (min n isearch-lazy-highlight-last-capture-face))
+ 	     (beg (car matches))
+ 	     (end (cadr matches))
+ 	     (ov  (make-overlay beg end)))
+ 	(push ov isearch-lazy-highlight-overlays)
+ 	(overlay-put ov 'priority (+ isearch-lazy-highlight-minimum-overlay-priority n))
+ 	(overlay-put ov 'face (intern (format "isearch-lazy-highlight-capture-%02d" m)))
+ 	(overlay-put ov 'window (selected-window)))
+       (setq n (1+ n))
+       (setq matches (cddr matches)))))
+ 
+ (eval-when-compile (require 'cl))
+ (flet ((isearch-lazy-highlight-define-capture-face
+ 	(num foreground-color background-color &rest other-face-attributes)
+ 	(custom-declare-face (intern (format "isearch-lazy-highlight-capture-%02d" num))
+ 			     `((((background dark))
+ 				(:background	,foreground-color
+ 				 :foreground	,background-color
+ 				 :underline	,(> num 0)
+ 				 :overline	,(> num 1)
+ 				 ,@other-face-attributes
+ 				 :inherit	lazy-highlight))
+ 			       (((background light))
+ 				(:background	,background-color
+ 				 :foreground	,foreground-color
+ 				 :underline	,(> num 0)
+ 				 :overline	,(> num 1)
+ 				 ,@other-face-attributes
+ 				 :inherit	lazy-highlight))
+ 			       (t
+ 				(:underline	t)))
+ 			       (concat "Face for lazy highlighting group "
+ 				       (number-to-string num)
+ 				       " of a regexp search.")
+ 			       :group 'lazy-highlight :group 'basic-faces)))
+   (isearch-lazy-highlight-define-capture-face 0 nil "cyan")
+   (isearch-lazy-highlight-define-capture-face 1 "blue" "yellow" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 2 "blue" "green" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 3 "white" "magenta" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 4 "yellow" "red" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 5 "yellow" "blue" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 6 "white" "blue" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 7 "cyan" "blue" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 8 "magenta" "blue" :weight 'bold)
+   (isearch-lazy-highlight-define-capture-face 9 "green" "blue" :weight 'bold))
+ 
  (defun isearch-resume (string regexp word forward message case-fold)
    "Resume an incremental search.
  STRING is the string or regexp searched for.

             reply	other threads:[~2010-11-22 10:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-22 10:38 Andrew Helsley [this message]
2010-11-23  0:59 ` [PATCH] isearch: lazy-highlighting of sub-exps of regexps Juri Linkov
2010-11-23 14:48   ` Stefan Monnier
2010-11-24  1:55     ` Juri Linkov
2010-11-24  2:43       ` Stefan Monnier
2010-11-24  5:03         ` Drew Adams
2010-11-25  1:39           ` Juri Linkov
2010-11-25  3:20             ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.00.1011220044390.17469@eon.cs.ucr.edu \
    --to=helsleya@cs.ucr.edu \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.