Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment?

Received: by 10.180.107.167 with SMTP id hd7mr1582187wib.0.1350183232827;
        Sat, 13 Oct 2012 19:53:52 -0700 (PDT)
Path: q10ni65116160wif.0!nntp.google.com!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.130.MISMATCH!xlned.com!feeder1.xlned.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nrc-news.nrc.ca!newsfeed.news.ucla.edu!usenet.stanford.edu!not-for-mail
From: Jambunathan K <kjambunat...@gmail.com>
Newsgroups: gnu.emacs.bug
Subject: bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment?
Date: Fri, 12 Oct 2012 01:54:30 +0530
Lines: 250
Sender: debbugs-submit-boun...@debbugs.gnu.org
Approved: bug-gnu-em...@gnu.org
Message-ID: <mailman.10781.1349987004.855.bug-gnu-emacs@gnu.org>
References: <81d37z271c.fsf@gmail.com>
NNTP-Posting-Host: lists.gnu.org
Mime-Version: 1.0
X-Trace: usenet.stanford.edu 1349987004 14889 208.118.235.17 (11 Oct 2012 20:23:24 GMT)
X-Complaints-To: action@cs.stanford.edu
To: 11...@debbugs.gnu.org
Envelope-to: bug-gnu-em...@gnu.org
X-Loop: help-debb...@gnu.org
Resent-From: Jambunathan K <kjambunat...@gmail.com>
Original-Sender: debbugs-submit-boun...@debbugs.gnu.org
Resent-CC: bug-gnu-em...@gnu.org
Resent-Date: Thu, 11 Oct 2012 20:24:01 +0000
Resent-Message-ID: <handler.11095.B11095.134998703514...@debbugs.gnu.org>
Resent-Sender: help-debb...@gnu.org
X-GNU-PR-Message: followup 11095
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=from:to:subject:references:date:in-reply-to:message-id:user-agent
	:mime-version:content-type;
	bh=BKYoZORnWM7wrFf2wt+B/3D6/KYSFrEfbJSgQcI5iA4=;
	b=waIYsDUxhkwH1pusSlXKsXQtEZD2lph+8Y/2c2Tbpl4TA2N8Wf9AgIzZg/2Tpbmg3K
	J3s51ePcsq1faksTUgrJ6aGL9E0c8BpzFurSuVBScoRStvje5iid9CxcOqT03j3xcx6Q
	PzKJZw9v/2tABgyn/Pq5SWOALyIQURpt9WM90xExaLRiPmgPvsWTR6YcVO4UuPOerK+E
	K/hG0medj2ljBtyJMePyLnb0PEkJwF6ZVoFit2l+vePpwX7nhmSAB1VNtJk8QqIAt/90
	xyfhENltCFel6JuEwwaJTtBBy5oI/POkbUEPwK5iUanyq5WxZrAIuLJW6CkO1xfjRxcW
	Xc+Q==
In-Reply-To: <81d37z271c....@gmail.com> (Jambunathan K.'s message of "Mon, 26
	Mar 2012 12:16:55 +0530")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)
X-BeenThere: debbugs-sub...@debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
Errors-To: debbugs-submit-boun...@debbugs.gnu.org
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.43
X-BeenThere: bug-gnu-em...@gnu.org
List-Id: "Bug reports for GNU Emacs,
	the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-requ...@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-em...@gnu.org>
List-Help: <mailto:bug-gnu-emacs-requ...@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-requ...@gnu.org?subject=subscribe>
Bytes: 12180
Content-Type: multipart/mixed; boundary="=-=-="

--=-=-=
Content-Type: text/plain


The attached patch, applies on top of earlier two patches. See
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11095#11

The patch allows highlighting of tag at point.  (Note that for all
practical purposes, tag at point is the symbol at point.) See
Part_I/Item-2 below for a usecase.


--=-=-=
Content-Type: text/plain


> Proposal is in two parts.  Part-I deals with `hi-lock-face-buffer'.
> Part-II deals with `unhighlight-regexp'.  Part-III has a dump of the
> current customization I have in my .emacs.
>
> I believe that my proposal is useful in general.  So I request that it
> be folded in to Emacs-24.1.
>
> Part-I: `hi-lock-face-buffer' & Co.
> ----------------------------------
>
> 1) Review the face names used in `hi-lock-face-defaults' and make the
>    faces customizable.  The defaults may not look good on a user's his
>    own font-lock configuration.
>
> 2) Make `hi-lock-face-buffer' use a different face on each invocation.  
>
>    Here is a real-world usecase for the above request.
>
>    As a programmer, I use highlighting to trace variable dependencies
>    within a function.  For example, in the example below, after
>    highlighting the variables in __different__ faces, I will come to the
>    conclusion that "a" depends on "d" and "tmp".
>
>      c = d;
>      b = c + tmp;
>      a = b;
>
>    And I use this very often to track variables and how they get their
>    values from.
>
>    If I were to use the default Emacs provided behaviour then I would
>    have to press M-n multiple times as I highlight more and more
>    symbols. (Typically I have 3-5 symbols highlighted before I turn off
>    highlighting.)
>
> See elisp snippet at the end of the mail.
>
>
> Part-II: `unhighlight-regexp'
> ------------------------------
>
> See usecase in Part-I/Item-2 
>
> 1) I want to selectively turn-off highlighting for certain regexps
>    (arguably) that _specific_ highlighted regexp cursor is stationed on.
>    This would happen when I decide that I don't want to factor a
>    particular variable for my current refactoring exercise.
>
>    I find the current behaviour of `unhighlight-regexp' slightly
>    tedious.  
>
>    1. There is no completion for which regexp I want to unhighlight and
>       I have to circle through `hi-lock-interactive-patterns'.
>
>    2. Browsing the `hi-lock-interactive-patterns' is tedious for the
>       following reasons:
>
>       - The order in which unhighlighting happens could totally be
>         unrelated to the order in which highlighting happens.  When I am
>         analyzing the variable flow, I don't want to do a "context
>         switch" trying to find out what item to choose from the
>         `unhighlight-regexp' menu.
>
> 2) I want to unhighlight all regexps.  This happens when I am done with
>    variable analysis.
>
>
> ps: I am not questioning the current defaults.  I am only saying that it
> the current behaviour is too generic to be immediately useful (atleast
> for my usecase) and so needs some sort of extra augmentation.
>
> Part-III: Elisp snippet
> -----------------------
>
> ;; Why should the color of the faces be encoded in the variable name?
> ;; Seems counter-intutitive to me.  I cannot relate to a hi-yellow
> ;; face customized to render in red.
>
> ;; (defvar hi-lock-face-defaults
> ;;   '("hi-yellow" "hi-pink" "hi-green" "hi-blue" "hi-black-b"
> ;;     "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb")
> ;;   "Default faces for hi-lock interactive functions.")
>
> ;; So roll out my own face for highlighting.  Make them
> ;; __customizable__.  Note that the name of the face doesn't say what
> ;; the color of the highlight will be.  Works for the color theme that
> ;; I have.
> (custom-set-faces
>  '(highlight1 ((t (:background "yellow" :foreground "black"))))
>  '(highlight2 ((t (:background "OrangeRed" :foreground "black"))))
>  '(highlight3 ((((class color) (background dark)) (:background "AntiqueWhite" :foreground "black"))))
>  '(highlight4 ((t (:background "SystemHotTrackingColor"))))
>  '(highlight5 ((t (:background "VioletRed" :foreground "black")))))
>
> ;; override the Emacs default
> (setq hi-lock-face-defaults
>       '("highlight1" "highlight2" "highlight3" "highlight4" "highlight5"))
>
> (defvar hi-lock-faces
>   (let ((l (copy-list hi-lock-face-defaults)))
>     (setcdr (last l) l))
>   "Circular list of faces in `hi-lock-face-defaults'.")
>
> ;; make `hi-lock-faces' buffer local
> (make-variable-buffer-local 'hi-lock-faces)
>
> (defun highlight-symbol ()
>   "Highlight symbol at point.  
> For illustartion only.  Note the use of `hi-lock-face-buffer'.
> Choose a new face from `hi-lock-faces' on each invocation.
> Overrides the default behaviour in vanilla Emacs which is to use
> the face at the head of the list."
>   (interactive)
>   (hi-lock-face-buffer
>    (concat "\\_<" (regexp-quote (thing-at-point 'symbol)) "\\_>")
>    ;; rotate the face list
>    (prog1 (car hi-lock-faces)
>      (setq hi-lock-faces (cdr hi-lock-faces)))))
>
> (defun my-unhighlight-regexp (arg)
>   "Wrapper around `unhighlight-regexp'.
> With a prefix argument, turn off all highlighting.
>
> TODO: Check if the symbol is right now on a highlighted regexp.
> If yes, unhighlight only that regexp."
>   (interactive "P")
>   (if arg
>       (mapc (lambda (p)
> 	      (unhighlight-regexp (car p)))
> 	    hi-lock-interactive-patterns)
>     (call-interactively 'unhighlight-regexp)))
>
>
>
>

-- 

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=bug11095-part3.patch
Content-Description: bug11095-part3.patch

=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el	2012-10-10 22:01:18 +0000
+++ lisp/hi-lock.el	2012-10-11 20:02:17 +0000
@@ -433,7 +433,7 @@ updated as you type."
   (interactive
    (list
     (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight line" (car regexp-history)))
+     (read-regexp "Regexp to highlight line"))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-lock-1))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -458,7 +458,7 @@ updated as you type."
   (interactive
    (list
     (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight" (car regexp-history)))
+     (read-regexp "Regexp to highlight"))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-lock-1))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -480,7 +480,7 @@ updated as you type."
    (list
     (hi-lock-regexp-okay
      (hi-lock-process-phrase
-      (read-regexp "Phrase to highlight" (car regexp-history))))
+      (read-regexp "Phrase to highlight")))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-lock-1))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -598,7 +598,7 @@ When `hi-lock-auto-select-face' is non-n
 from minibuffer with completion and history."
   (if hi-lock-auto-select-face
       ;; Return current head and rotate the face list.
-      (prog1 (car hi-lock-auto-select-face-defaults)
+      (prog1 (intern (car hi-lock-auto-select-face-defaults))
 	(setq hi-lock-auto-select-face-defaults
 	      (cdr hi-lock-auto-select-face-defaults)))
     (intern (completing-read

=== modified file 'lisp/replace.el'
--- lisp/replace.el	2012-10-04 19:28:11 +0000
+++ lisp/replace.el	2012-10-11 19:46:42 +0000
@@ -585,27 +585,32 @@ of `history-length', which see.")
 When PROMPT doesn't end with a colon and space, it adds a final \": \".
 If DEFAULTS is non-nil, it displays the first default in the prompt.
 
-Non-nil optional arg DEFAULTS is a string or a list of strings that
-are prepended to a list of standard default values, which include the
-string at point, the last isearch regexp, the last isearch string, and
-the last replacement regexp.
+Optional arg DEFAULTS is a string or a list of strings that are
+prepended to a list of standard default values, which include the
+tag at point, the last isearch regexp, the last isearch string,
+and the last replacement regexp.
 
 Non-nil HISTORY is a symbol to use for the history list.
 If HISTORY is nil, `regexp-history' is used."
-  (let* ((default (if (consp defaults) (car defaults) defaults))
-	 (defaults
+  (let* ((defaults
 	   (append
 	    (if (listp defaults) defaults (list defaults))
-	    (list (regexp-quote
-		   (or (funcall (or find-tag-default-function
+	    (list
+	     ;; Regexp for tag at point.
+	     (let* ((tagf (or find-tag-default-function
 				    (get major-mode 'find-tag-default-function)
 				    'find-tag-default))
-		       ""))
+		    (tag (funcall tagf)))
+	       (cond ((not tag) "")
+		     ((eq tagf 'find-tag-default)
+		      (format "\\_<%s\\_>" (regexp-quote tag)))
+		     (t (regexp-quote tag))))
 		  (car regexp-search-ring)
 		  (regexp-quote (or (car search-ring) ""))
 		  (car (symbol-value
 			query-replace-from-history-variable)))))
 	 (defaults (delete-dups (delq nil (delete "" defaults))))
+	 (default (car defaults))
 	 ;; Do not automatically add default to the history for empty input.
 	 (history-add-new-input nil)
 	 (input (read-from-minibuffer


--=-=-=--