diff options
| author | Juri Linkov | 2005-12-23 16:20:58 +0000 |
|---|---|---|
| committer | Juri Linkov | 2005-12-23 16:20:58 +0000 |
| commit | 81dc5714545cad6c19a8ea961087544d21db23f0 (patch) | |
| tree | 6b35a2880672ce1708de3ae447d56d352c9f01fe | |
| parent | 2d7409f20f2594b4406739d8ef073d6e5b952d06 (diff) | |
| download | emacs-81dc5714545cad6c19a8ea961087544d21db23f0.tar.gz emacs-81dc5714545cad6c19a8ea961087544d21db23f0.zip | |
(hi-lock-highlight-range): New variable.
(hi-lock-mode, hi-lock-unface-buffer): Call font-lock-fontify-buffer
only if font-lock-fontified is non-nil. Remove overlays.
(hi-lock-set-pattern): Call font-lock-fontify-buffer if
font-lock-fontified is non-nil, otherwise use overlays (instead of
text properties).
(hi-lock-string-serialize-hash, hi-lock-string-serialize-serial):
New variables.
(hi-lock-string-serialize) New function.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/hi-lock.el | 67 |
2 files changed, 66 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 320b6ec940f..960e304f2e3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2005-12-23 David Koppelman <koppel@ece.lsu.edu> | ||
| 2 | |||
| 3 | * hi-lock.el (hi-lock-highlight-range): New variable. | ||
| 4 | (hi-lock-mode, hi-lock-unface-buffer): Call font-lock-fontify-buffer | ||
| 5 | only if font-lock-fontified is non-nil. Remove overlays. | ||
| 6 | (hi-lock-set-pattern): Call font-lock-fontify-buffer if | ||
| 7 | font-lock-fontified is non-nil, otherwise use overlays (instead of | ||
| 8 | text properties). | ||
| 9 | (hi-lock-string-serialize-hash, hi-lock-string-serialize-serial): | ||
| 10 | New variables. | ||
| 11 | (hi-lock-string-serialize) New function. | ||
| 12 | |||
| 1 | 2005-12-23 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> | 13 | 2005-12-23 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> |
| 2 | 14 | ||
| 3 | * menu-bar.el (menu-find-file-existing): New function. | 15 | * menu-bar.el (menu-find-file-existing): New function. |
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index c3e2d814767..03f4a265bab 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el | |||
| @@ -97,6 +97,16 @@ of functions `hi-lock-mode' and `hi-lock-find-patterns'." | |||
| 97 | :type 'integer | 97 | :type 'integer |
| 98 | :group 'hi-lock) | 98 | :group 'hi-lock) |
| 99 | 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) | ||
| 109 | |||
| 100 | (defcustom hi-lock-exclude-modes | 110 | (defcustom hi-lock-exclude-modes |
| 101 | '(rmail-mode mime/viewer-mode gnus-article-mode) | 111 | '(rmail-mode mime/viewer-mode gnus-article-mode) |
| 102 | "List of major modes in which hi-lock will not run. | 112 | "List of major modes in which hi-lock will not run. |
| @@ -330,8 +340,8 @@ versions before 22 use the following in your .emacs file: | |||
| 330 | (when hi-lock-file-patterns | 340 | (when hi-lock-file-patterns |
| 331 | (font-lock-remove-keywords nil hi-lock-file-patterns) | 341 | (font-lock-remove-keywords nil hi-lock-file-patterns) |
| 332 | (setq hi-lock-file-patterns nil)) | 342 | (setq hi-lock-file-patterns nil)) |
| 333 | (if font-lock-mode | 343 | (remove-overlays nil nil 'hi-lock-overlay t) |
| 334 | (font-lock-fontify-buffer))) | 344 | (when font-lock-fontified (font-lock-fontify-buffer))) |
| 335 | (define-key-after menu-bar-edit-menu [hi-lock] nil) | 345 | (define-key-after menu-bar-edit-menu [hi-lock] nil) |
| 336 | (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t))) | 346 | (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t))) |
| 337 | 347 | ||
| @@ -461,7 +471,9 @@ interactive functions. \(See `hi-lock-interactive-patterns'.\) | |||
| 461 | (font-lock-remove-keywords nil (list keyword)) | 471 | (font-lock-remove-keywords nil (list keyword)) |
| 462 | (setq hi-lock-interactive-patterns | 472 | (setq hi-lock-interactive-patterns |
| 463 | (delq keyword hi-lock-interactive-patterns)) | 473 | (delq keyword hi-lock-interactive-patterns)) |
| 464 | (font-lock-fontify-buffer)))) | 474 | (remove-overlays |
| 475 | nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize regexp)) | ||
| 476 | (when font-lock-fontified (font-lock-fontify-buffer))))) | ||
| 465 | 477 | ||
| 466 | ;;;###autoload | 478 | ;;;###autoload |
| 467 | (defun hi-lock-write-interactive-patterns () | 479 | (defun hi-lock-write-interactive-patterns () |
| @@ -528,16 +540,25 @@ not suitable." | |||
| 528 | (unless (member pattern hi-lock-interactive-patterns) | 540 | (unless (member pattern hi-lock-interactive-patterns) |
| 529 | (font-lock-add-keywords nil (list pattern)) | 541 | (font-lock-add-keywords nil (list pattern)) |
| 530 | (push pattern hi-lock-interactive-patterns) | 542 | (push pattern hi-lock-interactive-patterns) |
| 531 | (let ((buffer-undo-list t) | 543 | (if font-lock-fontified |
| 532 | (inhibit-read-only t) | 544 | (font-lock-fontify-buffer) |
| 533 | (mod (buffer-modified-p))) | 545 | (let* ((serial (hi-lock-string-serialize regexp)) |
| 534 | (save-excursion | 546 | (range-min (- (point) (/ hi-lock-highlight-range 2))) |
| 535 | (goto-char (point-min)) | 547 | (range-max (+ (point) (/ hi-lock-highlight-range 2))) |
| 536 | (while (re-search-forward regexp (point-max) t) | 548 | (search-start |
| 537 | (put-text-property | 549 | (max (point-min) |
| 538 | (match-beginning 0) (match-end 0) 'face face) | 550 | (- range-min (max 0 (- range-max (point-max)))))) |
| 539 | (goto-char (match-end 0)))) | 551 | (search-end |
| 540 | (set-buffer-modified-p mod))))) | 552 | (min (point-max) |
| 553 | (+ range-max (max 0 (- (point-min) range-min)))))) | ||
| 554 | (save-excursion | ||
| 555 | (goto-char search-start) | ||
| 556 | (while (re-search-forward regexp search-end t) | ||
| 557 | (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) | ||
| 558 | (overlay-put overlay 'hi-lock-overlay t) | ||
| 559 | (overlay-put overlay 'hi-lock-overlay-regexp serial) | ||
| 560 | (overlay-put overlay 'face face)) | ||
| 561 | (goto-char (match-end 0))))))))) | ||
| 541 | 562 | ||
| 542 | (defun hi-lock-set-file-patterns (patterns) | 563 | (defun hi-lock-set-file-patterns (patterns) |
| 543 | "Replace file patterns list with PATTERNS and refontify." | 564 | "Replace file patterns list with PATTERNS and refontify." |
| @@ -577,6 +598,26 @@ not suitable." | |||
| 577 | (font-lock-add-keywords nil hi-lock-interactive-patterns)) | 598 | (font-lock-add-keywords nil hi-lock-interactive-patterns)) |
| 578 | (hi-lock-mode -1))) | 599 | (hi-lock-mode -1))) |
| 579 | 600 | ||
| 601 | (defvar hi-lock-string-serialize-hash | ||
| 602 | (make-hash-table :test 'equal) | ||
| 603 | "Hash table used to assign unique numbers to strings.") | ||
| 604 | |||
| 605 | (defvar hi-lock-string-serialize-serial 1 | ||
| 606 | "Number assigned to last new string in call to `hi-lock-string-serialize'. | ||
| 607 | A string is considered new if it had not previously been used in a call to | ||
| 608 | `hi-lock-string-serialize'.") | ||
| 609 | |||
| 610 | (defun hi-lock-string-serialize (string) | ||
| 611 | "Return unique serial number for STRING." | ||
| 612 | (interactive) | ||
| 613 | (let ((val (gethash string hi-lock-string-serialize-hash))) | ||
| 614 | (if val val | ||
| 615 | (puthash string | ||
| 616 | (setq hi-lock-string-serialize-serial | ||
| 617 | (1+ hi-lock-string-serialize-serial)) | ||
| 618 | hi-lock-string-serialize-hash) | ||
| 619 | hi-lock-string-serialize-serial))) | ||
| 620 | |||
| 580 | (provide 'hi-lock) | 621 | (provide 'hi-lock) |
| 581 | 622 | ||
| 582 | ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 | 623 | ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 |