]> code.delx.au - gnu-emacs/blobdiff - lisp/hi-lock.el
(Abbrevs): A @node line without explicit Prev, Next, and Up links.
[gnu-emacs] / lisp / hi-lock.el
index 03f4a265bab53b71fa1770985efef9a8c16bac78..fcba2466d01acd5cf50284c5ec064f81fdcfaa94 100644 (file)
@@ -1,7 +1,7 @@
 ;;; hi-lock.el --- minor mode for interactive automatic highlighting
 
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: David M. Koppelman, koppel@ee.lsu.edu
 ;; Keywords: faces, minor-mode, matching, display
@@ -91,7 +91,7 @@
 
 (defcustom hi-lock-file-patterns-range 10000
   "Limit of search in a buffer for hi-lock patterns.
-When a file is visited and hi-lock mode is on patterns starting
+When a file is visited and hi-lock mode is on, patterns starting
 up to this limit are added to font-lock's patterns.  See documentation
 of functions `hi-lock-mode' and `hi-lock-find-patterns'."
   :type 'integer
@@ -199,14 +199,14 @@ calls."
   "Regexp for finding hi-lock patterns at top of file.")
 
 (defvar hi-lock-archaic-interface-message-used nil
-  "True if user alerted that global-hi-lock-mode is now the global switch.
-Earlier versions of hi-lock used hi-lock-mode as the global switch,
-the message is issued if it appears that hi-lock-mode is used assuming
+  "True if user alerted that `global-hi-lock-mode' is now the global switch.
+Earlier versions of hi-lock used `hi-lock-mode' as the global switch;
+the message is issued if it appears that `hi-lock-mode' is used assuming
 that older functionality.  This variable avoids multiple reminders.")
 
 (defvar hi-lock-archaic-interface-deduce nil
-  "If non-nil, sometimes assume that hi-lock-mode means global-hi-lock-mode.
-Assumption is made if hi-lock-mode used in the *scratch* buffer while
+  "If non-nil, sometimes assume that `hi-lock-mode' means `global-hi-lock-mode'.
+Assumption is made if `hi-lock-mode' used in the *scratch* buffer while
 a library is being loaded.")
 
 (make-variable-buffer-local 'hi-lock-interactive-patterns)
@@ -257,14 +257,13 @@ a library is being loaded.")
 
 ;; Visible Functions
 
-
 ;;;###autoload
 (define-minor-mode hi-lock-mode
   "Toggle minor mode for interactively adding font-lock highlighting patterns.
 
-If ARG positive turn hi-lock on.  Issuing a hi-lock command will also
-turn hi-lock on; to turn hi-lock on in all buffers use
-global-hi-lock-mode or in your .emacs file (global-hi-lock-mode 1).
+If ARG positive, turn hi-lock on.  Issuing a hi-lock command will also
+turn hi-lock on.  To turn hi-lock on in all buffers use
+`global-hi-lock-mode' or in your .emacs file (global-hi-lock-mode 1).
 When hi-lock is turned on, a \"Regexp Highlighting\" submenu is added
 to the \"Edit\" menu.  The commands in the submenu, which can be
 called interactively, are:
@@ -284,10 +283,10 @@ called interactively, are:
   Remove highlighting on matches of REGEXP in current buffer.
 
 \\[hi-lock-write-interactive-patterns]
-  Write active REGEXPs into buffer as comments (if possible). They will
+  Write active REGEXPs into buffer as comments (if possible).  They will
   be read the next time file is loaded or when the \\[hi-lock-find-patterns] command
   is issued.  The inserted regexps are in the form of font lock keywords.
-  (See `font-lock-keywords') They may be edited and re-loaded with \\[hi-lock-find-patterns],
+  (See `font-lock-keywords'.)  They may be edited and re-loaded with \\[hi-lock-find-patterns],
   any valid `font-lock-keywords' form is acceptable.
 
 \\[hi-lock-find-patterns]
@@ -296,14 +295,16 @@ called interactively, are:
 When hi-lock is started and if the mode is not excluded, the
 beginning of the buffer is searched for lines of the form:
   Hi-lock: FOO
-where FOO is a list of patterns. These are added to the font lock keywords
-already present.  The patterns must start before position (number
-of characters into buffer) `hi-lock-file-patterns-range'.  Patterns
-will be read until
+where FOO is a list of patterns.  These are added to the font lock
+keywords already present.  The patterns must start before position
+\(number of characters into buffer) `hi-lock-file-patterns-range'.
+Patterns will be read until
  Hi-lock: end
-is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'."
+is found.  A mode is excluded if it's in the list `hi-lock-exclude-modes'."
   :group 'hi-lock
-  :lighter " H"
+  :lighter (:eval (if (or hi-lock-interactive-patterns
+                         hi-lock-file-patterns)
+                     " Hi" ""))
   :global nil
   :keymap hi-lock-map
   (when (and (equal (buffer-name) "*scratch*")
@@ -316,7 +317,7 @@ is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'."
       (warn
        "Possible archaic use of (hi-lock-mode).
 Use (global-hi-lock-mode 1) in .emacs to enable hi-lock for all buffers,
-use (hi-lock-mode 1) for individual buffers. For compatibility with Emacs
+use (hi-lock-mode 1) for individual buffers.  For compatibility with Emacs
 versions before 22 use the following in your .emacs file:
 
         (if (functionp 'global-hi-lock-mode)
@@ -364,7 +365,7 @@ versions before 22 use the following in your .emacs file:
 Interactively, prompt for REGEXP then FACE.  Buffer-local history
 list maintained for regexps, global history maintained for faces.
 \\<minibuffer-local-map>Use \\[next-history-element] and \\[previous-history-element] to retrieve next or previous history item.
-\(See info node `Minibuffer History')"
+\(See info node `Minibuffer History'.)"
   (interactive
    (list
     (hi-lock-regexp-okay
@@ -389,7 +390,7 @@ list maintained for regexps, global history maintained for faces.
 Interactively, prompt for REGEXP then FACE.  Buffer-local history
 list maintained for regexps, global history maintained for faces.
 \\<minibuffer-local-map>Use \\[next-history-element] and \\[previous-history-element] to retrieve next or previous history item.
-\(See info node `Minibuffer History')"
+\(See info node `Minibuffer History'.)"
   (interactive
    (list
     (hi-lock-regexp-okay
@@ -488,7 +489,9 @@ be found in variable `hi-lock-interactive-patterns'."
   (let ((beg (point)))
     (mapcar
      (lambda (pattern)
-       (insert (format "Hi-lock: (%s)\n" (prin1-to-string pattern))))
+       (insert (format "%s: (%s)\n"
+                      hi-lock-file-patterns-prefix
+                      (prin1-to-string pattern))))
      hi-lock-interactive-patterns)
     (comment-region beg (point)))
   (when (> (point) hi-lock-file-patterns-range)
@@ -538,7 +541,7 @@ not suitable."
   "Highlight REGEXP with face FACE."
   (let ((pattern (list regexp (list 0 (list 'quote face) t))))
     (unless (member pattern hi-lock-interactive-patterns)
-      (font-lock-add-keywords nil (list pattern))
+      (font-lock-add-keywords nil (list pattern) t)
       (push pattern hi-lock-interactive-patterns)
       (if font-lock-fontified
           (font-lock-fontify-buffer)
@@ -565,7 +568,7 @@ not suitable."
   (when (or hi-lock-file-patterns patterns)
     (font-lock-remove-keywords nil hi-lock-file-patterns)
     (setq hi-lock-file-patterns patterns)
-    (font-lock-add-keywords nil hi-lock-file-patterns)
+    (font-lock-add-keywords nil hi-lock-file-patterns t)
     (font-lock-fontify-buffer)))
 
 (defun hi-lock-find-patterns ()
@@ -592,10 +595,11 @@ not suitable."
         (message "Hi-lock added %d patterns." (length all-patterns))))))
 
 (defun hi-lock-font-lock-hook ()
-  "Add hi lock patterns to font-lock's."
+  "Add hi-lock patterns to font-lock's."
   (if font-lock-mode
-      (progn (font-lock-add-keywords nil hi-lock-file-patterns)
-            (font-lock-add-keywords nil hi-lock-interactive-patterns))
+      (progn
+       (font-lock-add-keywords nil hi-lock-file-patterns t)
+       (font-lock-add-keywords nil hi-lock-interactive-patterns t))
     (hi-lock-mode -1)))
 
 (defvar hi-lock-string-serialize-hash