unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 11095-done@debbugs.gnu.org
Subject: bug#11095: [PATCH] Re: bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment?
Date: Tue, 11 Dec 2012 02:07:58 +0530	[thread overview]
Message-ID: <87lid57ie1.fsf@gmail.com> (raw)
In-Reply-To: <jwvd2yhsr79.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 10 Dec 2012 13:34:25 -0500")

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

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> This patch makes sure that faces used for highlighting are always
>> distinct and recycles them only when it is inevitable.
>
> Installed with 2 changes:
> - replace "delete" with "remove" because it was applied to a list which
>   is reachable from other places (basically, from other buffer's
>   hi-lock--unused-faces).

Attaching a patch with following changes.  (This is the last lap)

1. Fix following bug when `font-lock-mode' is disabled.

    ,----
    | Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
    |   buffer-substring-no-properties(nil nil)
    |   (let* ((hi-text (buffer-substring-no-properties (previous-single-property-change (point) (quote face)) (next-single-property-change (point) (quote face))))) (progn (let ((--dolist-tail-- hi-lock-interactive-patterns)) (while --dolist-tail-- (let ((hi-lock-pattern (car --dolist-tail--))) (let ((regexp ...)) (if (string-match regexp hi-text) (setq regexps ...))) (setq --dolist-tail-- (cdr --dolist-tail--)))))))
    |   (and (memq (face-at-point) (mapcar (function hi-lock-keyword->face) hi-lock-interactive-patterns)) (let* ((hi-text (buffer-substring-no-properties (previous-single-property-change (point) (quote face)) (next-single-property-change (point) (quote face))))) (progn (let ((--dolist-tail-- hi-lock-interactive-patterns)) (while --dolist-tail-- (let ((hi-lock-pattern ...)) (let (...) (if ... ...)) (setq --dolist-tail-- (cdr --dolist-tail--))))))))
    |   (let ((regexps (quote nil))) (let ((regexp (get-char-property (point) (quote hi-lock-overlay-regexp)))) (if regexp (progn (setq regexps (cons regexp regexps))))) (and (memq (face-at-point) (mapcar (function hi-lock-keyword->face) hi-lock-interactive-patterns)) (let* ((hi-text (buffer-substring-no-properties (previous-single-property-change (point) (quote face)) (next-single-property-change (point) (quote face))))) (progn (let ((--dolist-tail-- hi-lock-interactive-patterns)) (while --dolist-tail-- (let (...) (let ... ...) (setq --dolist-tail-- ...))))))) regexps)
    |   hi-lock--regexps-at-point()
    |   (or (hi-lock--regexps-at-point) (mapcar (function car) hi-lock-interactive-patterns))
    |   (let* ((defaults (or (hi-lock--regexps-at-point) (mapcar (function car) hi-lock-interactive-patterns)))) (list (completing-read (if (null defaults) "Regexp to unhighlight: " (format "Regexp to unhighlight (default %s): " (car defaults))) hi-lock-interactive-patterns nil t nil nil defaults)))
    |   (cond (current-prefix-arg (list t)) ((and (display-popup-menus-p) (listp last-nonmenu-event) use-dialog-box) (catch (quote snafu) (or (x-popup-menu t (cons (quote keymap) (cons "Select Pattern to Unhighlight" (mapcar ... hi-lock-interactive-patterns)))) (throw (quote snafu) (quote ("")))))) (t (if hi-lock-interactive-patterns nil (error "No highlighting to remove")) (let* ((defaults (or (hi-lock--regexps-at-point) (mapcar (function car) hi-lock-interactive-patterns)))) (list (completing-read (if (null defaults) "Regexp to unhighlight: " (format "Regexp to unhighlight (default %s): " (car defaults))) hi-lock-interactive-patterns nil t nil nil defaults)))))
    |   call-interactively(unhighlight-regexp nil nil)
    `----

2. Add a NEWS entry.
3. Re-works how hi-lock--unused-faces is allocated.


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

=== modified file 'etc/NEWS'
--- etc/NEWS	2012-12-10 12:38:49 +0000
+++ etc/NEWS	2012-12-10 20:08:35 +0000
@@ -92,6 +92,12 @@ when its arg ADJACENT is non-nil (when c
 it works like the utility `uniq'.  Otherwise by default it deletes
 duplicate lines everywhere in the region without regard to adjacency.
 
+** Interactive highlighting
+*** New user variable `hi-lock-auto-select-face'.
+*** Unhighlighting command (`hi-lock-unface-buffer') now un-highlights
+text at point.  When called interactively with a non-nil prefix,
+removes all highlighting in current buffer.
+
 ** Tramp
 +++
 *** New connection method "adb", which allows to access Android

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-12-10 18:33:59 +0000
+++ lisp/ChangeLog	2012-12-10 20:19:36 +0000
@@ -1,5 +1,14 @@
 2012-12-10  Jambunathan K  <kjambunathan@gmail.com>
 
+	* hi-lock.el (hi-lock--regexps-at-point): When `font-lock-mode' is
+	disabled, highlighting will use overlays.  So use
+	`*-single-char-property-change' instead of
+	``*-single-property-change'.
+	(hi-lock-read-face-name): Initialize `hi-lock--unused-faces' only
+	once.
+
+2012-12-10  Jambunathan K  <kjambunathan@gmail.com>
+
 	* hi-lock.el: Refine the choice of default face.
 	(hi-lock-keyword->face): New function.  Use it wherever we used
 	cadadadr instead.

=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el	2012-12-10 18:33:59 +0000
+++ lisp/hi-lock.el	2012-12-10 19:42:51 +0000
@@ -478,8 +478,8 @@ updated as you type."
                (mapcar #'hi-lock-keyword->face hi-lock-interactive-patterns))
 	 (let* ((hi-text
 		 (buffer-substring-no-properties
-		  (previous-single-property-change (point) 'face)
-		  (next-single-property-change (point) 'face))))
+		  (previous-single-char-property-change (point) 'face)
+		  (next-single-char-property-change (point) 'face))))
 	   ;; Compute hi-lock patterns that match the
 	   ;; highlighted text at point.  Use this later in
 	   ;; during completing-read.
@@ -611,8 +611,10 @@ not suitable."
   "Return face for interactive highlighting.
 When `hi-lock-auto-select-face' is non-nil, just return the next face.
 Otherwise, read face name from minibuffer with completion and history."
-  (unless hi-lock-interactive-patterns
-    (setq hi-lock--unused-faces hi-lock-face-defaults))
+  (unless (or hi-lock-interactive-patterns hi-lock--unused-faces)
+    ;; This is the very first request for interactive highlighting.
+    ;; Initialize unused faces list.
+    (setq hi-lock--unused-faces (copy-sequence hi-lock-face-defaults)))
   (let* ((last-used-face
 	  (when hi-lock-interactive-patterns
 	    (face-name (hi-lock-keyword->face
@@ -628,7 +630,7 @@ Otherwise, read face name from minibuffe
 			  (car defaults))
 		  obarray 'facep t nil 'face-name-history defaults))
       ;; Update list of un-used faces.
-      (setq hi-lock--unused-faces (remove face hi-lock--unused-faces))
+      (setq hi-lock--unused-faces (delete face hi-lock--unused-faces))
       ;; Grow the list of defaults.
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))


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




> - introduced a helper hi-lock-keyword->face to get rid of those cadadadr
>   (some of which needed `cl' even it was not `require'd).
>
>
>         Stefan

  reply	other threads:[~2012-12-10 20:37 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 [this message]
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
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87lid57ie1.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=11095-done@debbugs.gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).