From: Jambunathan K <kjambunathan@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 11095@debbugs.gnu.org
Subject: bug#11095: [PATCH] Re: bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment?
Date: Mon, 10 Dec 2012 09:56:47 +0530 [thread overview]
Message-ID: <87ip8a352w.fsf@gmail.com> (raw)
In-Reply-To: <87pq2k6744.fsf@gmail.com> (Jambunathan K.'s message of "Sat, 08 Dec 2012 18:20:03 +0530")
[-- Attachment #1: Type: text/plain, Size: 261 bytes --]
This patch which /improves/ status quo. Applies cleanly on top of
earlier patch at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11095#94
This patch makes sure that faces used for highlighting are always
distinct and recycles them only when it is inevitable.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bug11095-rev111152-2.diff --]
[-- Type: text/x-diff, Size: 3477 bytes --]
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog 2012-12-10 04:18:24 +0000
+++ lisp/ChangeLog 2012-12-10 04:18:59 +0000
@@ -1,3 +1,11 @@
+2012-12-10 Jambunathan K <kjambunathan@gmail.com>
+
+ * hi-lock.el (hi-lock--last-face): Remove it.
+ (hi-lock--unused-faces): New variable, a free list of faces
+ available for highlighting text.
+ (hi-lock-unface-buffer, hi-lock-read-face-name): Propagate above
+ changes.
+
2012-12-08 Jambunathan K <kjambunathan@gmail.com>
* hi-lock.el (hi-lock--regexps-at-point): Use a better heuristic
=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el 2012-12-08 13:06:46 +0000
+++ lisp/hi-lock.el 2012-12-10 04:06:21 +0000
@@ -486,7 +486,9 @@ updated as you type."
(push regexp regexps))))))
regexps))
-(defvar-local hi-lock--last-face nil)
+(defvar-local hi-lock--unused-faces nil
+ "List of faces that is not used and is available for highlighting new text.
+Face names from this list come from `hi-lock-face-defaults'.")
;;;###autoload
(defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
@@ -544,9 +546,7 @@ then remove all hi-lock highlighting."
(setq regexp (car keyword))
(let ((face (cadr (cadr (cadr keyword)))))
;; Make `face' the next one to use by default.
- (setq hi-lock--last-face
- (cadr (member (symbol-name face)
- (reverse hi-lock-face-defaults)))))
+ (add-to-list 'hi-lock--unused-faces (face-name face)))
(font-lock-remove-keywords nil (list keyword))
(setq hi-lock-interactive-patterns
(delq keyword hi-lock-interactive-patterns))
@@ -609,20 +609,26 @@ 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."
- (let ((default (or (cadr (member hi-lock--last-face hi-lock-face-defaults))
- (car hi-lock-face-defaults))))
- (setq hi-lock--last-face
+ (unless hi-lock-interactive-patterns
+ (setq hi-lock--unused-faces hi-lock-face-defaults))
+ (let* ((last-used-face
+ (when hi-lock-interactive-patterns
+ (face-name (cadar (cdar (cdar hi-lock-interactive-patterns))))))
+ (defaults (append hi-lock--unused-faces
+ (cdr (member last-used-face hi-lock-face-defaults))
+ hi-lock-face-defaults))
+ face)
(if (and hi-lock-auto-select-face (not current-prefix-arg))
- default
- (completing-read
- (format "Highlight using face (default %s): " default)
- obarray 'facep t nil 'face-name-history
- (append (member default hi-lock-face-defaults)
- hi-lock-face-defaults))))
- (unless (member hi-lock--last-face hi-lock-face-defaults)
- (setq hi-lock-face-defaults
- (append hi-lock-face-defaults (list hi-lock--last-face))))
- (intern hi-lock--last-face)))
+ (setq face (or (pop hi-lock--unused-faces) (car defaults)))
+ (setq face (completing-read
+ (format "Highlight using face (default %s): "
+ (car defaults))
+ obarray 'facep t nil 'face-name-history defaults))
+ ;; Update list of un-used 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)))
(defun hi-lock-set-pattern (regexp face)
"Highlight REGEXP with face FACE."
next prev parent reply other threads:[~2012-12-10 4:26 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 [this message]
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
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=87ip8a352w.fsf@gmail.com \
--to=kjambunathan@gmail.com \
--cc=11095@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).