aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/hi-lock.el51
1 files changed, 40 insertions, 11 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 889b13cfa59..0dd5f6ef2e2 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -3,7 +3,7 @@
3;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 3;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4;; 2005, 2006, 2007 Free Software Foundation, Inc. 4;; 2005, 2006, 2007 Free Software Foundation, Inc.
5 5
6;; Author: David M. Koppelman, koppel@ee.lsu.edu 6;; Author: David M. Koppelman, koppel@ece.lsu.edu
7;; Keywords: faces, minor-mode, matching, display 7;; Keywords: faces, minor-mode, matching, display
8 8
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
@@ -33,7 +33,8 @@
33;; will remove the highlighting. Any existing face can be used for 33;; will remove the highlighting. Any existing face can be used for
34;; highlighting and a set of appropriate faces is provided. The 34;; highlighting and a set of appropriate faces is provided. The
35;; regexps can be written into the current buffer in a form that will 35;; regexps can be written into the current buffer in a form that will
36;; be recognized the next time the corresponding file is read. 36;; be recognized the next time the corresponding file is read (when
37;; file patterns is turned on).
37;; 38;;
38;; Applications: 39;; Applications:
39;; 40;;
@@ -60,6 +61,14 @@
60;; 61;;
61;; (global-hi-lock-mode 1) 62;; (global-hi-lock-mode 1)
62;; 63;;
64;; To enable the use of patterns found in files (presumably placed
65;; there by hi-lock) include the following in your .emacs file:
66;;
67;; (setq hi-lock-file-patterns-policy 'ask)
68;;
69;; If you get tired of being asked each time a file is loaded replace
70;; 'ask with a function that returns t if patterns should be read.
71;;
63;; You might also want to bind the hi-lock commands to more 72;; You might also want to bind the hi-lock commands to more
64;; finger-friendly sequences: 73;; finger-friendly sequences:
65 74
@@ -115,6 +124,12 @@ calls."
115 :type '(repeat symbol) 124 :type '(repeat symbol)
116 :group 'hi-lock) 125 :group 'hi-lock)
117 126
127(defvar hi-lock-file-patterns-policy 'never
128 "Specify when hi-lock should use patterns found in file.
129If 'ask, prompt when patterns found in buffer; if bound to a function,
130use patterns when function returns t (function is called with patterns
131as first argument); if nil or 'never or anything else, don't use file
132patterns.")
118 133
119(defgroup hi-lock-faces nil 134(defgroup hi-lock-faces nil
120 "Faces for hi-lock." 135 "Faces for hi-lock."
@@ -196,7 +211,7 @@ calls."
196 "History of regexps used for interactive fontification.") 211 "History of regexps used for interactive fontification.")
197 212
198(defvar hi-lock-file-patterns-prefix "Hi-lock" 213(defvar hi-lock-file-patterns-prefix "Hi-lock"
199 "Regexp for finding hi-lock patterns at top of file.") 214 "Search target for finding hi-lock patterns at top of file.")
200 215
201(defvar hi-lock-archaic-interface-message-used nil 216(defvar hi-lock-archaic-interface-message-used nil
202 "True if user alerted that `global-hi-lock-mode' is now the global switch. 217 "True if user alerted that `global-hi-lock-mode' is now the global switch.
@@ -283,17 +298,22 @@ called interactively, are:
283 Remove highlighting on matches of REGEXP in current buffer. 298 Remove highlighting on matches of REGEXP in current buffer.
284 299
285\\[hi-lock-write-interactive-patterns] 300\\[hi-lock-write-interactive-patterns]
286 Write active REGEXPs into buffer as comments (if possible). They will 301 Write active REGEXPs into buffer as comments (if possible). They may
287 be read the next time file is loaded or when the \\[hi-lock-find-patterns] command 302 be read the next time file is loaded or when the \\[hi-lock-find-patterns] command
288 is issued. The inserted regexps are in the form of font lock keywords. 303 is issued. The inserted regexps are in the form of font lock keywords.
289 (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns], 304 (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns],
290 any valid `font-lock-keywords' form is acceptable. 305 any valid `font-lock-keywords' form is acceptable. When a file is
306 loaded the patterns are read if `hi-lock-file-patterns-policy is
307 'ask and the user responds y to the prompt, or if
308 `hi-lock-file-patterns-policy' is bound to a function and that
309 function returns t.
291 310
292\\[hi-lock-find-patterns] 311\\[hi-lock-find-patterns]
293 Re-read patterns stored in buffer (in the format produced by \\[hi-lock-write-interactive-patterns]). 312 Re-read patterns stored in buffer (in the format produced by \\[hi-lock-write-interactive-patterns]).
294 313
295When hi-lock is started and if the mode is not excluded, the 314When hi-lock is started and if the mode is not excluded or patterns
296beginning of the buffer is searched for lines of the form: 315rejected, the beginning of the buffer is searched for lines of the
316form:
297 Hi-lock: FOO 317 Hi-lock: FOO
298where FOO is a list of patterns. These are added to the font lock 318where FOO is a list of patterns. These are added to the font lock
299keywords already present. The patterns must start before position 319keywords already present. The patterns must start before position
@@ -590,9 +610,18 @@ not suitable."
590 (setq all-patterns (append (read (current-buffer)) all-patterns)) 610 (setq all-patterns (append (read (current-buffer)) all-patterns))
591 (error (message "Invalid pattern list expression at %d" 611 (error (message "Invalid pattern list expression at %d"
592 (line-number-at-pos))))))) 612 (line-number-at-pos)))))))
593 (when hi-lock-mode (hi-lock-set-file-patterns all-patterns)) 613 (when (and all-patterns
594 (if (interactive-p) 614 hi-lock-mode
595 (message "Hi-lock added %d patterns." (length all-patterns)))))) 615 (cond
616 ((eq this-command 'hi-lock-find-patterns) t)
617 ((functionp hi-lock-file-patterns-policy)
618 (funcall hi-lock-file-patterns-policy all-patterns))
619 ((eq hi-lock-file-patterns-policy 'ask)
620 (y-or-n-p "Add patterns from this buffer to hi-lock? "))
621 (t nil)))
622 (hi-lock-set-file-patterns all-patterns)
623 (if (interactive-p)
624 (message "Hi-lock added %d patterns." (length all-patterns)))))))
596 625
597(defun hi-lock-font-lock-hook () 626(defun hi-lock-font-lock-hook ()
598 "Add hi-lock patterns to font-lock's." 627 "Add hi-lock patterns to font-lock's."