aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-12-06 11:17:11 -0500
committerStefan Monnier2012-12-06 11:17:11 -0500
commit853c1ffc037f4adc402bea59e3beb03860e63ff7 (patch)
treebc873047e39de03566dbf8a2bef474c9645a9ea5
parent1700db3c71ec3fde2e263b3325a5b5f5315a4ef9 (diff)
downloademacs-853c1ffc037f4adc402bea59e3beb03860e63ff7.tar.gz
emacs-853c1ffc037f4adc402bea59e3beb03860e63ff7.zip
* lisp/hi-lock.el: Rework the default face and the serialize regexp code.
(hi-lock--auto-select-face-defaults): Remove. (hi-lock-string-serialize-serial): Remove. (hi-lock--hashcons-hash): Rename from hi-lock-string-serialize-hash; make weak. (hi-lock--hashcons): Rename from hi-lock-string-serialize, return an equal string. (hi-lock-set-pattern): Adjust accordingly. (hi-lock--regexps-at-point): Simplify accordingly. (hi-lock--auto-select-face-defaults): Remove. (hi-lock--last-face): New var to replace it. (hi-lock-read-face-name): Rewrite. (hi-lock-unface-buffer): Arrange for the face to be the next default. Fixes: debbugs:11095
-rw-r--r--lisp/ChangeLog30
-rw-r--r--lisp/hi-lock.el102
2 files changed, 62 insertions, 70 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0c541a7d817..82b311acf0d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,11 +1,27 @@
12012-12-06 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * hi-lock.el: Rework the default face and the serialize regexp code.
4 (hi-lock--auto-select-face-defaults): Remove.
5 (hi-lock-string-serialize-serial): Remove.
6 (hi-lock--hashcons-hash): Rename from hi-lock-string-serialize-hash;
7 make weak.
8 (hi-lock--hashcons): Rename from hi-lock-string-serialize, return an
9 equal string.
10 (hi-lock-set-pattern): Adjust accordingly.
11 (hi-lock--regexps-at-point): Simplify accordingly.
12 (hi-lock--auto-select-face-defaults): Remove.
13 (hi-lock--last-face): New var to replace it.
14 (hi-lock-read-face-name): Rewrite (bug#11095).
15 (hi-lock-unface-buffer): Arrange for the face to be the next default.
16
12012-12-06 Michael Albinus <michael.albinus@gmx.de> 172012-12-06 Michael Albinus <michael.albinus@gmx.de>
2 18
3 * net/tramp.el (tramp-replace-environment-variables): Hide 19 * net/tramp.el (tramp-replace-environment-variables):
4 compiler warning. 20 Hide compiler warning.
5 (tramp-file-name-for-operation): Remove `executable-find', 21 (tramp-file-name-for-operation): Remove `executable-find',
6 `start-process', `call-process' and `call-process-region'. 22 `start-process', `call-process' and `call-process-region'.
7 23
8 * net/tramp-compat.el (top): Don't require 'tramp-util and 'tramp-vc. 24 * net/tramp-compat.el (top): Don't require 'tramp-util and 'tramp-vc.
9 25
10 * net/tramp-gvfs.el (tramp-gvfs-dbus-event-error): Ensure backward 26 * net/tramp-gvfs.el (tramp-gvfs-dbus-event-error): Ensure backward
11 compatibility. 27 compatibility.
@@ -54,8 +70,8 @@
54 * net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band): 70 * net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band):
55 Check return code of copy command. 71 Check return code of copy command.
56 72
57 * net/tramp-adb.el (tramp-adb-sdk-dir, tramp-adb-prompt): Use 73 * net/tramp-adb.el (tramp-adb-sdk-dir, tramp-adb-prompt):
58 group `tramp'. Add version. 74 Use group `tramp'. Add version.
59 75
602012-12-05 Chong Yidong <cyd@gnu.org> 762012-12-05 Chong Yidong <cyd@gnu.org>
61 77
@@ -207,8 +223,8 @@
207 * progmodes/perl-mode.el (perl-current-defun-name): New. 223 * progmodes/perl-mode.el (perl-current-defun-name): New.
208 (perl-mode): Use it. 224 (perl-mode): Use it.
209 225
210 * progmodes/scheme.el (scheme-mode-variables, dsssl-mode): Use 226 * progmodes/scheme.el (scheme-mode-variables, dsssl-mode):
211 lisp-current-defun-name. 227 Use lisp-current-defun-name.
212 228
213 * textmodes/tex-mode.el (tex-current-defun-name): New. 229 * textmodes/tex-mode.el (tex-current-defun-name): New.
214 (tex-common-initialization): Use it. 230 (tex-common-initialization): Use it.
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 5496a7581c3..02635eea413 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -1,4 +1,4 @@
1;;; hi-lock.el --- minor mode for interactive automatic highlighting 1;;; hi-lock.el --- minor mode for interactive automatic highlighting -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 2000-2012 Free Software Foundation, Inc. 3;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 4
@@ -138,7 +138,7 @@ patterns."
138(defcustom hi-lock-auto-select-face nil 138(defcustom hi-lock-auto-select-face nil
139 "Non-nil if highlighting commands should not prompt for face names. 139 "Non-nil if highlighting commands should not prompt for face names.
140When non-nil, each hi-lock command will cycle through faces in 140When non-nil, each hi-lock command will cycle through faces in
141`hi-lock-face-defaults'." 141`hi-lock-face-defaults' without prompting."
142 :type 'boolean 142 :type 'boolean
143 :version "24.4") 143 :version "24.4")
144 144
@@ -218,14 +218,6 @@ When non-nil, each hi-lock command will cycle through faces in
218 "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb") 218 "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb")
219 "Default faces for hi-lock interactive functions.") 219 "Default faces for hi-lock interactive functions.")
220 220
221(defvar-local hi-lock--auto-select-face-defaults
222 (let ((l (copy-sequence hi-lock-face-defaults)))
223 (setcdr (last l) l))
224 "Circular list of faces used for interactive highlighting.
225When `hi-lock-auto-select-face' is non-nil, use the face at the
226head of this list for next interactive highlighting. See also
227`hi-lock-read-face-name'.")
228
229(define-obsolete-variable-alias 'hi-lock-regexp-history 221(define-obsolete-variable-alias 'hi-lock-regexp-history
230 'regexp-history 222 'regexp-history
231 "23.1") 223 "23.1")
@@ -479,15 +471,8 @@ updated as you type."
479 (let ((regexps '())) 471 (let ((regexps '()))
480 ;; When using overlays, there is no ambiguity on the best 472 ;; When using overlays, there is no ambiguity on the best
481 ;; choice of regexp. 473 ;; choice of regexp.
482 (let ((desired-serial (get-char-property 474 (let ((regexp (get-char-property (point) 'hi-lock-overlay-regexp)))
483 (point) 'hi-lock-overlay-regexp))) 475 (when regexp (push regexp regexps)))
484 (when desired-serial
485 (catch 'regexp
486 (maphash
487 (lambda (regexp serial)
488 (when (= serial desired-serial)
489 (push regexp regexps)))
490 hi-lock-string-serialize-hash))))
491 ;; With font-locking on, check if the cursor is on an highlighted text. 476 ;; With font-locking on, check if the cursor is on an highlighted text.
492 ;; Checking for hi-lock face is a good heuristic. 477 ;; Checking for hi-lock face is a good heuristic.
493 (and (string-match "\\`hi-lock-" (face-name (face-at-point))) 478 (and (string-match "\\`hi-lock-" (face-name (face-at-point)))
@@ -503,6 +488,8 @@ updated as you type."
503 (if (string-match regexp hi-text) 488 (if (string-match regexp hi-text)
504 (push regexp regexps)))))))) 489 (push regexp regexps))))))))
505 490
491(defvar-local hi-lock--last-face nil)
492
506;;;###autoload 493;;;###autoload
507(defalias 'unhighlight-regexp 'hi-lock-unface-buffer) 494(defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
508;;;###autoload 495;;;###autoload
@@ -529,9 +516,7 @@ then remove all hi-lock highlighting."
529 (list (car pattern) 516 (list (car pattern)
530 (format 517 (format
531 "%s (%s)" (car pattern) 518 "%s (%s)" (car pattern)
532 (symbol-name 519 (cadr (cadr (cadr pattern))))
533 (car
534 (cdr (car (cdr (car (cdr pattern))))))))
535 (cons nil nil) 520 (cons nil nil)
536 (car pattern))) 521 (car pattern)))
537 hi-lock-interactive-patterns)))) 522 hi-lock-interactive-patterns))))
@@ -557,11 +542,16 @@ then remove all hi-lock highlighting."
557 (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns 542 (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns
558 (list (assoc regexp hi-lock-interactive-patterns)))) 543 (list (assoc regexp hi-lock-interactive-patterns))))
559 (when keyword 544 (when keyword
545 (let ((face (cadr (cadr (cadr keyword)))))
546 ;; Make `face' the next one to use by default.
547 (setq hi-lock--last-face
548 (cadr (member (symbol-name face)
549 (reverse hi-lock-face-defaults)))))
560 (font-lock-remove-keywords nil (list keyword)) 550 (font-lock-remove-keywords nil (list keyword))
561 (setq hi-lock-interactive-patterns 551 (setq hi-lock-interactive-patterns
562 (delq keyword hi-lock-interactive-patterns)) 552 (delq keyword hi-lock-interactive-patterns))
563 (remove-overlays 553 (remove-overlays
564 nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize regexp)) 554 nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons regexp))
565 (when font-lock-fontified (font-lock-fontify-buffer))))) 555 (when font-lock-fontified (font-lock-fontify-buffer)))))
566 556
567;;;###autoload 557;;;###autoload
@@ -616,28 +606,28 @@ not suitable."
616 regexp)) 606 regexp))
617 607
618(defun hi-lock-read-face-name () 608(defun hi-lock-read-face-name ()
619 "Return face name for interactive highlighting. 609 "Return face for interactive highlighting.
620When `hi-lock-auto-select-face' is non-nil, just return the next face. 610When `hi-lock-auto-select-face' is non-nil, just return the next face.
621Otherwise, read face name from minibuffer with completion and history." 611Otherwise, read face name from minibuffer with completion and history."
622 (if hi-lock-auto-select-face 612 (let ((default (or (cadr (member hi-lock--last-face hi-lock-face-defaults))
623 ;; Return current head and rotate the face list. 613 (car hi-lock-face-defaults))))
624 (pop hi-lock--auto-select-face-defaults) 614 (setq hi-lock--last-face
625 (intern (completing-read 615 (if (and hi-lock-auto-select-face (not current-prefix-arg))
626 "Highlight using face: " 616 default
627 obarray 'facep t 617 (completing-read
628 (cons (car hi-lock-face-defaults) 618 (format "Highlight using face (default %s): " default)
629 (let ((prefix 619 obarray 'facep t nil 'face-name-history
630 (try-completion 620 (append (member default hi-lock-face-defaults)
631 (substring (car hi-lock-face-defaults) 0 1) 621 hi-lock-face-defaults))))
632 hi-lock-face-defaults))) 622 (unless (member hi-lock--last-face hi-lock-face-defaults)
633 (if (and (stringp prefix) 623 (setq hi-lock-face-defaults
634 (not (equal prefix (car hi-lock-face-defaults)))) 624 (append hi-lock-face-defaults (list hi-lock--last-face))))
635 (length prefix) 0))) 625 (intern hi-lock--last-face)))
636 'face-name-history
637 (cdr hi-lock-face-defaults)))))
638 626
639(defun hi-lock-set-pattern (regexp face) 627(defun hi-lock-set-pattern (regexp face)
640 "Highlight REGEXP with face FACE." 628 "Highlight REGEXP with face FACE."
629 ;; Hashcons the regexp, so it can be passed to remove-overlays later.
630 (setq regexp (hi-lock--hashcons regexp))
641 (let ((pattern (list regexp (list 0 (list 'quote face) t)))) 631 (let ((pattern (list regexp (list 0 (list 'quote face) t))))
642 (unless (member pattern hi-lock-interactive-patterns) 632 (unless (member pattern hi-lock-interactive-patterns)
643 (push pattern hi-lock-interactive-patterns) 633 (push pattern hi-lock-interactive-patterns)
@@ -645,8 +635,7 @@ Otherwise, read face name from minibuffer with completion and history."
645 (progn 635 (progn
646 (font-lock-add-keywords nil (list pattern) t) 636 (font-lock-add-keywords nil (list pattern) t)
647 (font-lock-fontify-buffer)) 637 (font-lock-fontify-buffer))
648 (let* ((serial (hi-lock-string-serialize regexp)) 638 (let* ((range-min (- (point) (/ hi-lock-highlight-range 2)))
649 (range-min (- (point) (/ hi-lock-highlight-range 2)))
650 (range-max (+ (point) (/ hi-lock-highlight-range 2))) 639 (range-max (+ (point) (/ hi-lock-highlight-range 2)))
651 (search-start 640 (search-start
652 (max (point-min) 641 (max (point-min)
@@ -659,7 +648,7 @@ Otherwise, read face name from minibuffer with completion and history."
659 (while (re-search-forward regexp search-end t) 648 (while (re-search-forward regexp search-end t)
660 (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) 649 (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
661 (overlay-put overlay 'hi-lock-overlay t) 650 (overlay-put overlay 'hi-lock-overlay t)
662 (overlay-put overlay 'hi-lock-overlay-regexp serial) 651 (overlay-put overlay 'hi-lock-overlay-regexp regexp)
663 (overlay-put overlay 'face face)) 652 (overlay-put overlay 'face face))
664 (goto-char (match-end 0))))))))) 653 (goto-char (match-end 0)))))))))
665 654
@@ -709,27 +698,14 @@ Otherwise, read face name from minibuffer with completion and history."
709 (font-lock-add-keywords nil hi-lock-file-patterns t) 698 (font-lock-add-keywords nil hi-lock-file-patterns t)
710 (font-lock-add-keywords nil hi-lock-interactive-patterns t))) 699 (font-lock-add-keywords nil hi-lock-interactive-patterns t)))
711 700
712(defvar hi-lock-string-serialize-hash 701(defvar hi-lock--hashcons-hash
713 ;; FIXME: don't map strings to numbers but to unique strings via 702 (make-hash-table :test 'equal :weakness t)
714 ;; hash-consing, with a weak hash-table. 703 "Hash table used to hash cons regexps.")
715 (make-hash-table :test 'equal)
716 "Hash table used to assign unique numbers to strings.")
717 704
718(defvar hi-lock-string-serialize-serial 1 705(defun hi-lock--hashcons (string)
719 "Number assigned to last new string in call to `hi-lock-string-serialize'. 706 "Return unique object equal to STRING."
720A string is considered new if it had not previously been used in a call to 707 (or (gethash string hi-lock--hashcons-hash)
721`hi-lock-string-serialize'.") 708 (puthash string string hi-lock--hashcons-hash)))
722
723(defun hi-lock-string-serialize (string)
724 "Return unique serial number for STRING."
725 (interactive)
726 (let ((val (gethash string hi-lock-string-serialize-hash)))
727 (if val val
728 (puthash string
729 (setq hi-lock-string-serialize-serial
730 (1+ hi-lock-string-serialize-serial))
731 hi-lock-string-serialize-hash)
732 hi-lock-string-serialize-serial)))
733 709
734(defun hi-lock-unload-function () 710(defun hi-lock-unload-function ()
735 "Unload the Hi-Lock library." 711 "Unload the Hi-Lock library."