all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: 11095@debbugs.gnu.org
Subject: bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment?
Date: Fri, 12 Oct 2012 23:48:55 +0530	[thread overview]
Message-ID: <874nlz5zao.fsf@gmail.com> (raw)
In-Reply-To: <81d37z271c.fsf@gmail.com> (Jambunathan K.'s message of "Mon, 26 Mar 2012 12:16:55 +0530")

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]


I am attaching a patch that is 5-th and last in the series for my
proposal.  This patch applies on top of the 4-th patch visible here:
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11095#26.

The patch adds an ability to un-highlight all highlighted text in the
buffer via a prefix arg.  See Part-II/Item-2 below.

ps: I am following up this mail with a consolidated patch, just in case
someone needs to try stuff out.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bug11095-part5.patch --]
[-- Type: text/x-diff, Size: 3121 bytes --]

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-10-12 16:19:16 +0000
+++ lisp/ChangeLog	2012-10-12 18:03:45 +0000
@@ -1,5 +1,10 @@
 2012-10-12  Jambunathan K  <kjambunathan@gmail.com>
 
+	* hi-lock.el (hi-lock-unface-buffer): With prefix arg, unhighlight
+	all hi-lock patterns in buffer.
+
+2012-10-12  Jambunathan K  <kjambunathan@gmail.com>
+
 	* hi-lock.el (hi-lock-unface-buffer): Prompt user with useful
 	defaults.  Specifically, if cursor is on an highlighted text,
 	offer a regexp that matches that text as the default.  Update

=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el	2012-10-12 16:19:16 +0000
+++ lisp/hi-lock.el	2012-10-12 17:35:34 +0000
@@ -491,17 +491,18 @@ updated as you type."
 ;;;###autoload
 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
 ;;;###autoload
-(defun hi-lock-unface-buffer (regexp)
+(defun hi-lock-unface-buffer (regexp &optional prefix-arg)
   "Remove highlighting of each match to REGEXP set by hi-lock.
-Interactively, prompt for REGEXP.  If the cursor is on a
-previously highlighted text and if the associated regexp can be
-inferred via simple heuristics, offer that regexp as default.
-Otherwise, prompt for REGEXP with completion and limit the
-choices to only those regexps used previously with hi-lock
-commands.
+Interactively, when PREFIX-ARG is non-nil, unhighlight all
+highlighted text in current buffer.  When PREFIX-ARG is nil,
+prompt for REGEXP.  If the cursor is on a previously highlighted
+text and if the associated regexp can be inferred via simple
+heuristics, offer that regexp as default.  Otherwise, prompt for
+REGEXP with completion and limit the choices to only those
+regexps used previously with hi-lock commands.
 
-If this command is invoked via menu, make no attempt to infer
-REGEXP from text at point."
+If this command is invoked via menu, pop-up a list of currently
+highlighted patterns."
   (interactive
    (if (and (display-popup-menus-p)
 	    (listp last-nonmenu-event)
@@ -570,18 +571,22 @@ REGEXP from text at point."
 		      ;; a reasonable default.
 		      (caar candidate-hi-lock-patterns))))))
        (list
+	(and (not current-prefix-arg)
 	(completing-read "Regexp to unhighlight: "
 			 (or candidate-hi-lock-patterns
 			     hi-lock-interactive-patterns)
-			 nil t default-regexp)))))
-  (let ((keyword (assoc regexp hi-lock-interactive-patterns)))
+			      nil t default-regexp))
+	current-prefix-arg))))
+  (dolist (re (if (not prefix-arg) (list regexp)
+		(mapcar #'car hi-lock-interactive-patterns)))
+    (let ((keyword (assoc re hi-lock-interactive-patterns)))
     (when keyword
       (font-lock-remove-keywords nil (list keyword))
       (setq hi-lock-interactive-patterns
             (delq keyword hi-lock-interactive-patterns))
       (remove-overlays
-       nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize regexp))
-      (when font-lock-fontified (font-lock-fontify-buffer)))))
+	 nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize re))
+	(when font-lock-fontified (font-lock-fontify-buffer))))))
 
 ;;;###autoload
 (defun hi-lock-write-interactive-patterns ()


[-- Attachment #3: Type: text/plain, Size: 5127 bytes --]


> 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)))
>
>
>
>

-- 

  parent reply	other threads:[~2012-10-12 18:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26  6:46 bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment? Jambunathan K
2012-10-10 20:21 ` bug#11095: [PATCH] " Jambunathan K
2012-12-04 21:14   ` Stefan Monnier
2012-12-04 21:39     ` Drew Adams
2012-12-04 21:57       ` Stefan Monnier
2012-12-04 22:43         ` Drew Adams
2012-12-05  3:46           ` Stefan Monnier
2012-12-05 22:15             ` Jambunathan K
2012-12-06  1:14               ` Stefan Monnier
2012-12-06  5:06     ` Jambunathan K
2012-12-06 14:50       ` Jambunathan K
2012-12-06 19:16       ` Stefan Monnier
2012-12-06 19:36         ` Drew Adams
2012-12-06 21:26         ` Jambunathan K
2012-12-06 21:36           ` Stefan Monnier
2012-12-06 22:23             ` Jambunathan K
2012-12-07  4:07               ` Stefan Monnier
2012-12-07  4:46                 ` Jambunathan K
2012-12-07 16:55                   ` Stefan Monnier
2012-12-08 12:50                     ` Jambunathan K
2012-12-10  4:26                       ` Jambunathan K
2012-12-10 18:34                         ` Stefan Monnier
2012-12-10 20:37                           ` Jambunathan K
2012-12-10 21:27                             ` Stefan Monnier
2012-10-10 22:08 ` Jambunathan K
2012-10-11 20:24 ` Jambunathan K
2012-10-11 20:33   ` Jambunathan K
2012-10-11 22:41   ` Juri Linkov
2012-10-12  4:30     ` Jambunathan K
2012-10-13 16:10       ` Juri Linkov
2012-10-13 17:28         ` Jambunathan K
2012-10-12 16:17 ` Jambunathan K
2012-10-12 18:18 ` Jambunathan K [this message]
2012-10-12 19:32 ` bug#11095: [FINAL] " Jambunathan K

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=874nlz5zao.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=11095@debbugs.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.