;; hi-lock mode and adds a "Regexp Highlighting" entry
;; to the edit menu.
;;
-;; (hi-lock-mode 1)
+;; (global-hi-lock-mode 1)
;;
;; You might also want to bind the hi-lock commands to more
;; finger-friendly sequences:
(defvar hi-lock-file-patterns-prefix "Hi-lock"
"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
+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
+a library is being loaded.")
+
(make-variable-buffer-local 'hi-lock-interactive-patterns)
(put 'hi-lock-interactive-patterns 'permanent-local t)
(make-variable-buffer-local 'hi-lock-regexp-history)
;;;###autoload
-(define-minor-mode hi-lock-buffer-mode
+(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. 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:
+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:
\\[highlight-regexp] REGEXP FACE
Highlight matches of pattern REGEXP in current buffer with FACE.
:lighter " H"
:global nil
:keymap hi-lock-map
- (if hi-lock-buffer-mode
+ (when (and (equal (buffer-name) "*scratch*")
+ load-in-progress
+ (not (interactive-p))
+ (not hi-lock-archaic-interface-message-used))
+ (setq hi-lock-archaic-interface-message-used t)
+ (if hi-lock-archaic-interface-deduce
+ (global-hi-lock-mode hi-lock-mode)
+ (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
+versions before 22 use the following in your .emacs file:
+
+ (if (functionp 'global-hi-lock-mode)
+ (global-hi-lock-mode 1)
+ (hi-lock-mode 1))
+")))
+ (if hi-lock-mode
;; Turned on.
(progn
+ (unless font-lock-mode (font-lock-mode 1))
(define-key-after menu-bar-edit-menu [hi-lock]
(cons "Regexp Highlighting" hi-lock-menu))
(hi-lock-find-patterns)
- (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t))
+ (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t))
;; Turned off.
- (when hi-lock-interactive-patterns
- (font-lock-remove-keywords nil hi-lock-interactive-patterns)
- (setq hi-lock-interactive-patterns nil))
- (when hi-lock-file-patterns
- (font-lock-remove-keywords nil hi-lock-file-patterns)
- (setq hi-lock-file-patterns nil))
- (hi-lock-refontify)
+ (when (or hi-lock-interactive-patterns
+ hi-lock-file-patterns)
+ (when hi-lock-interactive-patterns
+ (font-lock-remove-keywords nil hi-lock-interactive-patterns)
+ (setq hi-lock-interactive-patterns nil))
+ (when hi-lock-file-patterns
+ (font-lock-remove-keywords nil hi-lock-file-patterns)
+ (setq hi-lock-file-patterns nil))
+ (if font-lock-mode
+ (font-lock-fontify-buffer)))
(define-key-after menu-bar-edit-menu [hi-lock] nil)
(remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)))
;;;###autoload
-(define-global-minor-mode hi-lock-mode
- hi-lock-buffer-mode turn-on-hi-lock-if-enabled
- :group 'hi-lock-interactive-text-highlighting)
-
+(define-global-minor-mode global-hi-lock-mode
+ hi-lock-mode turn-on-hi-lock-if-enabled
+ :group 'hi-lock)
+
(defun turn-on-hi-lock-if-enabled ()
+ (setq hi-lock-archaic-interface-message-used t)
(unless (memq major-mode hi-lock-exclude-modes)
- (hi-lock-buffer-mode 1)))
+ (hi-lock-mode 1)))
;;;###autoload
(defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer)
(cons (or (car hi-lock-regexp-history) "") 1 )
nil nil 'hi-lock-regexp-history))
(hi-lock-read-face-name)))
- (or (facep face) (setq face 'rwl-yellow))
- (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1))
+ (or (facep face) (setq face 'hi-yellow))
+ (unless hi-lock-mode (hi-lock-mode 1))
(hi-lock-set-pattern
;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ?
;; or a trailing $ in REGEXP will be interpreted correctly.
(cons (or (car hi-lock-regexp-history) "") 1 )
nil nil 'hi-lock-regexp-history))
(hi-lock-read-face-name)))
- (or (facep face) (setq face 'rwl-yellow))
- (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1))
+ (or (facep face) (setq face 'hi-yellow))
+ (unless hi-lock-mode (hi-lock-mode 1))
(hi-lock-set-pattern regexp face))
;;;###autoload
(cons (or (car hi-lock-regexp-history) "") 1 )
nil nil 'hi-lock-regexp-history)))
(hi-lock-read-face-name)))
- (or (facep face) (setq face 'rwl-yellow))
- (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1))
+ (or (facep face) (setq face 'hi-yellow))
+ (unless hi-lock-mode (hi-lock-mode 1))
(hi-lock-set-pattern regexp face))
;;;###autoload
(font-lock-remove-keywords nil (list keyword))
(setq hi-lock-interactive-patterns
(delq keyword hi-lock-interactive-patterns))
- (hi-lock-refontify))))
+ (font-lock-fontify-buffer))))
;;;###autoload
(defun hi-lock-write-interactive-patterns ()
`highlight-regexp' and `highlight-lines-matching-regexp'; they can
be found in variable `hi-lock-interactive-patterns'."
(interactive)
- (let ((prefix (format "%s %s:" (or comment-start "") "Hi-lock")))
- (when (> (+ (point) (length prefix)) hi-lock-file-patterns-range)
- (beep)
- (message
- "Warning, inserted keywords not close enough to top of file."))
+ (if (null hi-lock-interactive-patterns)
+ (error "There are no interactive patterns"))
+ (let ((beg (point)))
(mapcar
(lambda (pattern)
- (insert (format "%s (%s) %s\n"
- prefix (prin1-to-string pattern) (or comment-end ""))))
- hi-lock-interactive-patterns)))
-
+ (insert (format "Hi-lock: (%s)\n" (prin1-to-string pattern))))
+ hi-lock-interactive-patterns)
+ (comment-region beg (point)))
+ (when (> (point) hi-lock-file-patterns-range)
+ (warn "Inserted keywords not close enough to top of file")))
;; Implementation Functions
(font-lock-remove-keywords nil hi-lock-file-patterns)
(setq hi-lock-file-patterns patterns)
(font-lock-add-keywords nil hi-lock-file-patterns)
- (hi-lock-refontify)))
-
-(defun hi-lock-refontify ()
- "Unfontify then refontify buffer. Used when hi-lock patterns change."
- (interactive)
- (if font-lock-mode
- (font-lock-fontify-buffer)))
+ (font-lock-fontify-buffer)))
(defun hi-lock-find-patterns ()
"Find patterns in current buffer for hi-lock."
(setq all-patterns (append (read (current-buffer)) all-patterns))
(error (message "Invalid pattern list expression at %d"
(line-number-at-pos)))))))
- (when hi-lock-buffer-mode (hi-lock-set-file-patterns all-patterns))
+ (when hi-lock-mode (hi-lock-set-file-patterns all-patterns))
(if (interactive-p)
(message "Hi-lock added %d patterns." (length all-patterns))))))
(defun hi-lock-font-lock-hook ()
"Add hi lock patterns to font-lock's."
- (when font-lock-mode
- (font-lock-add-keywords nil hi-lock-file-patterns)
- (font-lock-add-keywords nil hi-lock-interactive-patterns)))
+ (if font-lock-mode
+ (progn (font-lock-add-keywords nil hi-lock-file-patterns)
+ (font-lock-add-keywords nil hi-lock-interactive-patterns))
+ (hi-lock-mode -1)))
(provide 'hi-lock)