comparison lisp/hi-lock.el @ 90261:7beb78bc1f8e

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-97 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 616-696) - Add lisp/mh-e/.arch-inventory - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords. - lisp/gnus/ChangeLog: Remove duplicate entry * gnus--rel--5.10 (patch 147-181) - Update from CVS - Merge from emacs--cvs-trunk--0 - Update from CVS: lisp/mml.el (mml-preview): Doc fix. - Update from CVS: texi/message.texi: Fix default values. - Update from CVS: texi/gnus.texi (RSS): Addition.
author Miles Bader <miles@gnu.org>
date Mon, 16 Jan 2006 08:37:27 +0000
parents fa0da9b57058 edd5b99fd103
children d6f8fe3307c8
comparison
equal deleted inserted replaced
90260:0ca0d9181b5e 90261:7beb78bc1f8e
56 ;; 56 ;;
57 ;; Put the following code in your .emacs file. This turns on 57 ;; Put the following code in your .emacs file. This turns on
58 ;; hi-lock mode and adds a "Regexp Highlighting" entry 58 ;; hi-lock mode and adds a "Regexp Highlighting" entry
59 ;; to the edit menu. 59 ;; to the edit menu.
60 ;; 60 ;;
61 ;; (hi-lock-mode 1) 61 ;; (global-hi-lock-mode 1)
62 ;; 62 ;;
63 ;; You might also want to bind the hi-lock commands to more 63 ;; You might also want to bind the hi-lock commands to more
64 ;; finger-friendly sequences: 64 ;; finger-friendly sequences:
65 65
66 ;; (define-key hi-lock-map "\C-z\C-h" 'highlight-lines-matching-regexp) 66 ;; (define-key hi-lock-map "\C-z\C-h" 'highlight-lines-matching-regexp)
82 ;;; Code: 82 ;;; Code:
83 83
84 (eval-and-compile 84 (eval-and-compile
85 (require 'font-lock)) 85 (require 'font-lock))
86 86
87 (defgroup hi-lock-interactive-text-highlighting nil 87 (defgroup hi-lock nil
88 "Interactively add and remove font-lock patterns for highlighting text." 88 "Interactively add and remove font-lock patterns for highlighting text."
89 :group 'faces) 89 :link '(custom-manual "(emacs)Highlight Interactively")
90 90 :group 'font-lock)
91 ;;;###autoload
92 (defcustom hi-lock-mode nil
93 "Toggle hi-lock, for interactively adding font-lock text-highlighting patterns."
94 :set (lambda (symbol value)
95 (hi-lock-mode (or value 0)))
96 :initialize 'custom-initialize-default
97 :type 'boolean
98 :group 'hi-lock-interactive-text-highlighting
99 :require 'hi-lock)
100 91
101 (defcustom hi-lock-file-patterns-range 10000 92 (defcustom hi-lock-file-patterns-range 10000
102 "Limit of search in a buffer for hi-lock patterns. 93 "Limit of search in a buffer for hi-lock patterns.
103 When a file is visited and hi-lock mode is on patterns starting 94 When a file is visited and hi-lock mode is on patterns starting
104 up to this limit are added to font-lock's patterns. See documentation 95 up to this limit are added to font-lock's patterns. See documentation
105 of functions `hi-lock-mode' and `hi-lock-find-patterns'." 96 of functions `hi-lock-mode' and `hi-lock-find-patterns'."
106 :type 'integer 97 :type 'integer
107 :group 'hi-lock-interactive-text-highlighting) 98 :group 'hi-lock)
99
100 (defcustom hi-lock-highlight-range 200000
101 "Size of area highlighted by hi-lock when font-lock not active.
102 Font-lock is not active in buffers that do their own highlighting,
103 such as the buffer created by `list-colors-display'. In those buffers
104 hi-lock patterns will only be applied over a range of
105 `hi-lock-highlight-range' characters. If font-lock is active then
106 highlighting will be applied throughout the buffer."
107 :type 'integer
108 :group 'hi-lock)
108 109
109 (defcustom hi-lock-exclude-modes 110 (defcustom hi-lock-exclude-modes
110 '(rmail-mode mime/viewer-mode gnus-article-mode) 111 '(rmail-mode mime/viewer-mode gnus-article-mode)
111 "List of major modes in which hi-lock will not run. 112 "List of major modes in which hi-lock will not run.
112 For security reasons since font lock patterns can specify function 113 For security reasons since font lock patterns can specify function
113 calls." 114 calls."
114 :type '(repeat symbol) 115 :type '(repeat symbol)
115 :group 'hi-lock-interactive-text-highlighting) 116 :group 'hi-lock)
116 117
117 118
118 (defgroup hi-lock-faces nil 119 (defgroup hi-lock-faces nil
119 "Faces for hi-lock." 120 "Faces for hi-lock."
120 :group 'hi-lock-interactive-text-highlighting) 121 :group 'hi-lock
122 :group 'faces)
121 123
122 (defface hi-yellow 124 (defface hi-yellow
123 '((((min-colors 88) (background dark)) 125 '((((min-colors 88) (background dark))
124 (:background "yellow1" :foreground "black")) 126 (:background "yellow1" :foreground "black"))
125 (((background dark)) (:background "yellow" :foreground "black")) 127 (((background dark)) (:background "yellow" :foreground "black"))
194 "History of regexps used for interactive fontification.") 196 "History of regexps used for interactive fontification.")
195 197
196 (defvar hi-lock-file-patterns-prefix "Hi-lock" 198 (defvar hi-lock-file-patterns-prefix "Hi-lock"
197 "Regexp for finding hi-lock patterns at top of file.") 199 "Regexp for finding hi-lock patterns at top of file.")
198 200
201 (defvar hi-lock-archaic-interface-message-used nil
202 "True if user alerted that `global-hi-lock-mode' is now the global switch.
203 Earlier versions of hi-lock used `hi-lock-mode' as the global switch,
204 the message is issued if it appears that `hi-lock-mode' is used assuming
205 that older functionality. This variable avoids multiple reminders.")
206
207 (defvar hi-lock-archaic-interface-deduce nil
208 "If non-nil, sometimes assume that `hi-lock-mode' means `global-hi-lock-mode'.
209 Assumption is made if `hi-lock-mode' used in the *scratch* buffer while
210 a library is being loaded.")
211
199 (make-variable-buffer-local 'hi-lock-interactive-patterns) 212 (make-variable-buffer-local 'hi-lock-interactive-patterns)
200 (put 'hi-lock-interactive-patterns 'permanent-local t) 213 (put 'hi-lock-interactive-patterns 'permanent-local t)
201 (make-variable-buffer-local 'hi-lock-regexp-history) 214 (make-variable-buffer-local 'hi-lock-regexp-history)
202 (put 'hi-lock-regexp-history 'permanent-local t) 215 (put 'hi-lock-regexp-history 'permanent-local t)
203 (make-variable-buffer-local 'hi-lock-file-patterns) 216 (make-variable-buffer-local 'hi-lock-file-patterns)
240 (define-key hi-lock-map "\C-xwp" 'highlight-phrase) 253 (define-key hi-lock-map "\C-xwp" 'highlight-phrase)
241 (define-key hi-lock-map "\C-xwh" 'highlight-regexp) 254 (define-key hi-lock-map "\C-xwh" 'highlight-regexp)
242 (define-key hi-lock-map "\C-xwr" 'unhighlight-regexp) 255 (define-key hi-lock-map "\C-xwr" 'unhighlight-regexp)
243 (define-key hi-lock-map "\C-xwb" 'hi-lock-write-interactive-patterns) 256 (define-key hi-lock-map "\C-xwb" 'hi-lock-write-interactive-patterns)
244 257
245 (unless (assq 'hi-lock-mode minor-mode-map-alist)
246 (setq minor-mode-map-alist (cons (cons 'hi-lock-mode hi-lock-map)
247 minor-mode-map-alist)))
248
249 (unless (assq 'hi-lock-mode minor-mode-alist)
250 (setq minor-mode-alist (cons '(hi-lock-mode " H") minor-mode-alist)))
251
252
253 ;; Visible Functions 258 ;; Visible Functions
254 259
255 260 ;;;###autoload
256 ;;;###autoload 261 (define-minor-mode hi-lock-mode
257 (defun hi-lock-mode (&optional arg)
258 "Toggle minor mode for interactively adding font-lock highlighting patterns. 262 "Toggle minor mode for interactively adding font-lock highlighting patterns.
259 263
260 If ARG positive turn hi-lock on. Issuing a hi-lock command will also 264 If ARG positive, turn hi-lock on. Issuing a hi-lock command will also
261 turn hi-lock on. When hi-lock is turned on, a \"Regexp Highlighting\" 265 turn hi-lock on. To turn hi-lock on in all buffers use
262 submenu is added to the \"Edit\" menu. The commands in the submenu, 266 `global-hi-lock-mode' or in your .emacs file (global-hi-lock-mode 1).
263 which can be called interactively, are: 267 When hi-lock is turned on, a \"Regexp Highlighting\" submenu is added
268 to the \"Edit\" menu. The commands in the submenu, which can be
269 called interactively, are:
264 270
265 \\[highlight-regexp] REGEXP FACE 271 \\[highlight-regexp] REGEXP FACE
266 Highlight matches of pattern REGEXP in current buffer with FACE. 272 Highlight matches of pattern REGEXP in current buffer with FACE.
267 273
268 \\[highlight-phrase] PHRASE FACE 274 \\[highlight-phrase] PHRASE FACE
293 already present. The patterns must start before position (number 299 already present. The patterns must start before position (number
294 of characters into buffer) `hi-lock-file-patterns-range'. Patterns 300 of characters into buffer) `hi-lock-file-patterns-range'. Patterns
295 will be read until 301 will be read until
296 Hi-lock: end 302 Hi-lock: end
297 is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'." 303 is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'."
298 (interactive) 304 :group 'hi-lock
299 (let ((hi-lock-mode-prev hi-lock-mode)) 305 :lighter (:eval (if (or hi-lock-interactive-patterns
300 (setq hi-lock-mode 306 hi-lock-file-patterns)
301 (if (null arg) (not hi-lock-mode) 307 " Hi" ""))
302 (> (prefix-numeric-value arg) 0))) 308 :global nil
303 ;; Turned on. 309 :keymap hi-lock-map
304 (when (and (not hi-lock-mode-prev) hi-lock-mode) 310 (when (and (equal (buffer-name) "*scratch*")
305 (add-hook 'find-file-hook 'hi-lock-find-file-hook) 311 load-in-progress
306 (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook) 312 (not (interactive-p))
307 (when (eq nil font-lock-defaults) 313 (not hi-lock-archaic-interface-message-used))
308 (setq font-lock-defaults '(nil))) 314 (setq hi-lock-archaic-interface-message-used t)
309 (unless font-lock-mode 315 (if hi-lock-archaic-interface-deduce
310 (font-lock-mode 1)) 316 (global-hi-lock-mode hi-lock-mode)
311 (define-key-after menu-bar-edit-menu [hi-lock] 317 (warn
312 (cons "Regexp Highlighting" hi-lock-menu)) 318 "Possible archaic use of (hi-lock-mode).
313 (dolist (buffer (buffer-list)) 319 Use (global-hi-lock-mode 1) in .emacs to enable hi-lock for all buffers,
314 (with-current-buffer buffer (hi-lock-find-patterns)))) 320 use (hi-lock-mode 1) for individual buffers. For compatibility with Emacs
321 versions before 22 use the following in your .emacs file:
322
323 (if (functionp 'global-hi-lock-mode)
324 (global-hi-lock-mode 1)
325 (hi-lock-mode 1))
326 ")))
327 (if hi-lock-mode
328 ;; Turned on.
329 (progn
330 (unless font-lock-mode (font-lock-mode 1))
331 (define-key-after menu-bar-edit-menu [hi-lock]
332 (cons "Regexp Highlighting" hi-lock-menu))
333 (hi-lock-find-patterns)
334 (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t))
315 ;; Turned off. 335 ;; Turned off.
316 (when (and hi-lock-mode-prev (not hi-lock-mode)) 336 (when (or hi-lock-interactive-patterns
317 (dolist (buffer (buffer-list)) 337 hi-lock-file-patterns)
318 (with-current-buffer buffer 338 (when hi-lock-interactive-patterns
319 (when (or hi-lock-interactive-patterns hi-lock-file-patterns) 339 (font-lock-remove-keywords nil hi-lock-interactive-patterns)
320 (font-lock-remove-keywords nil hi-lock-interactive-patterns) 340 (setq hi-lock-interactive-patterns nil))
321 (font-lock-remove-keywords nil hi-lock-file-patterns) 341 (when hi-lock-file-patterns
322 (setq hi-lock-interactive-patterns nil 342 (font-lock-remove-keywords nil hi-lock-file-patterns)
323 hi-lock-file-patterns nil) 343 (setq hi-lock-file-patterns nil))
324 (when font-lock-mode (hi-lock-refontify))))) 344 (remove-overlays nil nil 'hi-lock-overlay t)
325 (define-key-after menu-bar-edit-menu [hi-lock] nil) 345 (when font-lock-fontified (font-lock-fontify-buffer)))
326 (remove-hook 'find-file-hook 'hi-lock-find-file-hook) 346 (define-key-after menu-bar-edit-menu [hi-lock] nil)
327 (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook)))) 347 (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)))
328 348
349 ;;;###autoload
350 (define-global-minor-mode global-hi-lock-mode
351 hi-lock-mode turn-on-hi-lock-if-enabled
352 :group 'hi-lock)
353
354 (defun turn-on-hi-lock-if-enabled ()
355 (setq hi-lock-archaic-interface-message-used t)
356 (unless (memq major-mode hi-lock-exclude-modes)
357 (hi-lock-mode 1)))
329 358
330 ;;;###autoload 359 ;;;###autoload
331 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer) 360 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer)
332 ;;;###autoload 361 ;;;###autoload
333 (defun hi-lock-line-face-buffer (regexp &optional face) 362 (defun hi-lock-line-face-buffer (regexp &optional face)
342 (hi-lock-regexp-okay 371 (hi-lock-regexp-okay
343 (read-from-minibuffer "Regexp to highlight line: " 372 (read-from-minibuffer "Regexp to highlight line: "
344 (cons (or (car hi-lock-regexp-history) "") 1 ) 373 (cons (or (car hi-lock-regexp-history) "") 1 )
345 nil nil 'hi-lock-regexp-history)) 374 nil nil 'hi-lock-regexp-history))
346 (hi-lock-read-face-name))) 375 (hi-lock-read-face-name)))
347 (unless hi-lock-mode (hi-lock-mode)) 376 (or (facep face) (setq face 'hi-yellow))
348 (or (facep face) (setq face 'rwl-yellow)) 377 (unless hi-lock-mode (hi-lock-mode 1))
349 (hi-lock-set-pattern 378 (hi-lock-set-pattern
350 ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ? 379 ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ?
351 ;; or a trailing $ in REGEXP will be interpreted correctly. 380 ;; or a trailing $ in REGEXP will be interpreted correctly.
352 (list (concat "^.*\\(?:" regexp "\\).*$") (list 0 (list 'quote face) t)))) 381 (concat "^.*\\(?:" regexp "\\).*$") face))
353 382
354 383
355 ;;;###autoload 384 ;;;###autoload
356 (defalias 'highlight-regexp 'hi-lock-face-buffer) 385 (defalias 'highlight-regexp 'hi-lock-face-buffer)
357 ;;;###autoload 386 ;;;###autoload
367 (hi-lock-regexp-okay 396 (hi-lock-regexp-okay
368 (read-from-minibuffer "Regexp to highlight: " 397 (read-from-minibuffer "Regexp to highlight: "
369 (cons (or (car hi-lock-regexp-history) "") 1 ) 398 (cons (or (car hi-lock-regexp-history) "") 1 )
370 nil nil 'hi-lock-regexp-history)) 399 nil nil 'hi-lock-regexp-history))
371 (hi-lock-read-face-name))) 400 (hi-lock-read-face-name)))
372 (or (facep face) (setq face 'rwl-yellow)) 401 (or (facep face) (setq face 'hi-yellow))
373 (unless hi-lock-mode (hi-lock-mode)) 402 (unless hi-lock-mode (hi-lock-mode 1))
374 (hi-lock-set-pattern (list regexp (list 0 (list 'quote face) t)))) 403 (hi-lock-set-pattern regexp face))
375 404
376 ;;;###autoload 405 ;;;###autoload
377 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) 406 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
378 ;;;###autoload 407 ;;;###autoload
379 (defun hi-lock-face-phrase-buffer (regexp &optional face) 408 (defun hi-lock-face-phrase-buffer (regexp &optional face)
387 (hi-lock-process-phrase 416 (hi-lock-process-phrase
388 (read-from-minibuffer "Phrase to highlight: " 417 (read-from-minibuffer "Phrase to highlight: "
389 (cons (or (car hi-lock-regexp-history) "") 1 ) 418 (cons (or (car hi-lock-regexp-history) "") 1 )
390 nil nil 'hi-lock-regexp-history))) 419 nil nil 'hi-lock-regexp-history)))
391 (hi-lock-read-face-name))) 420 (hi-lock-read-face-name)))
392 (or (facep face) (setq face 'rwl-yellow)) 421 (or (facep face) (setq face 'hi-yellow))
393 (unless hi-lock-mode (hi-lock-mode)) 422 (unless hi-lock-mode (hi-lock-mode 1))
394 (hi-lock-set-pattern (list regexp (list 0 (list 'quote face) t)))) 423 (hi-lock-set-pattern regexp face))
395 424
396 ;;;###autoload 425 ;;;###autoload
397 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer) 426 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
398 ;;;###autoload 427 ;;;###autoload
399 (defun hi-lock-unface-buffer (regexp) 428 (defun hi-lock-unface-buffer (regexp)
441 (let ((keyword (assoc regexp hi-lock-interactive-patterns))) 470 (let ((keyword (assoc regexp hi-lock-interactive-patterns)))
442 (when keyword 471 (when keyword
443 (font-lock-remove-keywords nil (list keyword)) 472 (font-lock-remove-keywords nil (list keyword))
444 (setq hi-lock-interactive-patterns 473 (setq hi-lock-interactive-patterns
445 (delq keyword hi-lock-interactive-patterns)) 474 (delq keyword hi-lock-interactive-patterns))
446 (hi-lock-refontify)))) 475 (remove-overlays
476 nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize regexp))
477 (when font-lock-fontified (font-lock-fontify-buffer)))))
447 478
448 ;;;###autoload 479 ;;;###autoload
449 (defun hi-lock-write-interactive-patterns () 480 (defun hi-lock-write-interactive-patterns ()
450 "Write interactively added patterns, if any, into buffer at point. 481 "Write interactively added patterns, if any, into buffer at point.
451 482
452 Interactively added patterns are those normally specified using 483 Interactively added patterns are those normally specified using
453 `highlight-regexp' and `highlight-lines-matching-regexp'; they can 484 `highlight-regexp' and `highlight-lines-matching-regexp'; they can
454 be found in variable `hi-lock-interactive-patterns'." 485 be found in variable `hi-lock-interactive-patterns'."
455 (interactive) 486 (interactive)
456 (let ((prefix (format "%s %s:" (or comment-start "") "Hi-lock"))) 487 (if (null hi-lock-interactive-patterns)
457 (when (> (+ (point) (length prefix)) hi-lock-file-patterns-range) 488 (error "There are no interactive patterns"))
458 (beep) 489 (let ((beg (point)))
459 (message
460 "Warning, inserted keywords not close enough to top of file."))
461 (mapcar 490 (mapcar
462 (lambda (pattern) 491 (lambda (pattern)
463 (insert (format "%s (%s) %s\n" 492 (insert (format "%s: (%s)\n"
464 prefix (prin1-to-string pattern) (or comment-end "")))) 493 hi-lock-file-patterns-prefix
465 hi-lock-interactive-patterns))) 494 (prin1-to-string pattern))))
466 495 hi-lock-interactive-patterns)
496 (comment-region beg (point)))
497 (when (> (point) hi-lock-file-patterns-range)
498 (warn "Inserted keywords not close enough to top of file")))
467 499
468 ;; Implementation Functions 500 ;; Implementation Functions
469 501
470 (defun hi-lock-process-phrase (phrase) 502 (defun hi-lock-process-phrase (phrase)
471 "Convert regexp PHRASE to a regexp that matches phrases. 503 "Convert regexp PHRASE to a regexp that matches phrases.
503 (if (and (stringp prefix) 535 (if (and (stringp prefix)
504 (not (equal prefix (car hi-lock-face-history)))) 536 (not (equal prefix (car hi-lock-face-history))))
505 (length prefix) 0))) 537 (length prefix) 0)))
506 '(hi-lock-face-history . 0)))) 538 '(hi-lock-face-history . 0))))
507 539
508 (defun hi-lock-find-file-hook () 540 (defun hi-lock-set-pattern (regexp face)
509 "Add hi-lock patterns, if present." 541 "Highlight REGEXP with face FACE."
510 (hi-lock-find-patterns)) 542 (let ((pattern (list regexp (list 0 (list 'quote face) t))))
511
512 (defun hi-lock-current-line (&optional end)
513 "Return line number of line at point.
514 Optional argument END is maximum excursion."
515 (interactive)
516 (save-excursion
517 (beginning-of-line)
518 (1+ (count-lines 1 (or end (point))))))
519
520 (defun hi-lock-set-pattern (pattern)
521 "Add PATTERN to list of interactively highlighted patterns and refontify."
522 (hi-lock-set-patterns (list pattern)))
523
524 (defun hi-lock-set-patterns (patterns)
525 "Add PATTERNS to list of interactively highlighted patterns and refontify.."
526 (dolist (pattern patterns)
527 (unless (member pattern hi-lock-interactive-patterns) 543 (unless (member pattern hi-lock-interactive-patterns)
528 (font-lock-add-keywords nil (list pattern)) 544 (font-lock-add-keywords nil (list pattern) t)
529 (add-to-list 'hi-lock-interactive-patterns pattern))) 545 (push pattern hi-lock-interactive-patterns)
530 (hi-lock-refontify)) 546 (if font-lock-fontified
547 (font-lock-fontify-buffer)
548 (let* ((serial (hi-lock-string-serialize regexp))
549 (range-min (- (point) (/ hi-lock-highlight-range 2)))
550 (range-max (+ (point) (/ hi-lock-highlight-range 2)))
551 (search-start
552 (max (point-min)
553 (- range-min (max 0 (- range-max (point-max))))))
554 (search-end
555 (min (point-max)
556 (+ range-max (max 0 (- (point-min) range-min))))))
557 (save-excursion
558 (goto-char search-start)
559 (while (re-search-forward regexp search-end t)
560 (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
561 (overlay-put overlay 'hi-lock-overlay t)
562 (overlay-put overlay 'hi-lock-overlay-regexp serial)
563 (overlay-put overlay 'face face))
564 (goto-char (match-end 0)))))))))
531 565
532 (defun hi-lock-set-file-patterns (patterns) 566 (defun hi-lock-set-file-patterns (patterns)
533 "Replace file patterns list with PATTERNS and refontify." 567 "Replace file patterns list with PATTERNS and refontify."
534 (when (or hi-lock-file-patterns patterns) 568 (when (or hi-lock-file-patterns patterns)
535 (font-lock-remove-keywords nil hi-lock-file-patterns) 569 (font-lock-remove-keywords nil hi-lock-file-patterns)
536 (setq hi-lock-file-patterns patterns) 570 (setq hi-lock-file-patterns patterns)
537 (font-lock-add-keywords nil hi-lock-file-patterns) 571 (font-lock-add-keywords nil hi-lock-file-patterns t)
538 (hi-lock-refontify))) 572 (font-lock-fontify-buffer)))
539
540 (defun hi-lock-refontify ()
541 "Unfontify then refontify buffer. Used when hi-lock patterns change."
542 (interactive)
543 (unless font-lock-mode (font-lock-mode 1))
544 (font-lock-fontify-buffer))
545 573
546 (defun hi-lock-find-patterns () 574 (defun hi-lock-find-patterns ()
547 "Find patterns in current buffer for hi-lock." 575 "Find patterns in current buffer for hi-lock."
548 (interactive) 576 (interactive)
549 (unless (memq major-mode hi-lock-exclude-modes) 577 (unless (memq major-mode hi-lock-exclude-modes)
559 (while (and (re-search-forward target-regexp (+ (point) 100) t) 587 (while (and (re-search-forward target-regexp (+ (point) 100) t)
560 (not (looking-at "\\s-*end"))) 588 (not (looking-at "\\s-*end")))
561 (condition-case nil 589 (condition-case nil
562 (setq all-patterns (append (read (current-buffer)) all-patterns)) 590 (setq all-patterns (append (read (current-buffer)) all-patterns))
563 (error (message "Invalid pattern list expression at %d" 591 (error (message "Invalid pattern list expression at %d"
564 (hi-lock-current-line))))))) 592 (line-number-at-pos)))))))
565 (when hi-lock-mode (hi-lock-set-file-patterns all-patterns)) 593 (when hi-lock-mode (hi-lock-set-file-patterns all-patterns))
566 (if (interactive-p) 594 (if (interactive-p)
567 (message "Hi-lock added %d patterns." (length all-patterns)))))) 595 (message "Hi-lock added %d patterns." (length all-patterns))))))
568 596
569 (defun hi-lock-font-lock-hook () 597 (defun hi-lock-font-lock-hook ()
570 "Add hi lock patterns to font-lock's." 598 "Add hi lock patterns to font-lock's."
571 (when hi-lock-mode 599 (if font-lock-mode
572 (font-lock-add-keywords nil hi-lock-file-patterns) 600 (progn
573 (font-lock-add-keywords nil hi-lock-interactive-patterns))) 601 (font-lock-add-keywords nil hi-lock-file-patterns t)
602 (font-lock-add-keywords nil hi-lock-interactive-patterns t))
603 (hi-lock-mode -1)))
604
605 (defvar hi-lock-string-serialize-hash
606 (make-hash-table :test 'equal)
607 "Hash table used to assign unique numbers to strings.")
608
609 (defvar hi-lock-string-serialize-serial 1
610 "Number assigned to last new string in call to `hi-lock-string-serialize'.
611 A string is considered new if it had not previously been used in a call to
612 `hi-lock-string-serialize'.")
613
614 (defun hi-lock-string-serialize (string)
615 "Return unique serial number for STRING."
616 (interactive)
617 (let ((val (gethash string hi-lock-string-serialize-hash)))
618 (if val val
619 (puthash string
620 (setq hi-lock-string-serialize-serial
621 (1+ hi-lock-string-serialize-serial))
622 hi-lock-string-serialize-hash)
623 hi-lock-string-serialize-serial)))
574 624
575 (provide 'hi-lock) 625 (provide 'hi-lock)
576 626
577 ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 627 ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066
578 ;;; hi-lock.el ends here 628 ;;; hi-lock.el ends here