diff options
| author | Stefan Monnier | 1999-12-07 06:31:57 +0000 |
|---|---|---|
| committer | Stefan Monnier | 1999-12-07 06:31:57 +0000 |
| commit | 3708dfe933b3c567c39ee5619b22bbb4c128aca1 (patch) | |
| tree | 12f89d1b59e752b07529fc8d510377ce599a939f | |
| parent | 707ad06002b6d134339b1df083fad19ba274d41d (diff) | |
| download | emacs-3708dfe933b3c567c39ee5619b22bbb4c128aca1.tar.gz emacs-3708dfe933b3c567c39ee5619b22bbb4c128aca1.zip | |
(font-lock-default-fontify-region): Fix subtle
off-by-one problem that could force re-fontifying the whole buffer.
(font-lock-remove-keywords): New function.
(font-lock-add-keywords): Use the new function to ensure idempotence.
| -rw-r--r-- | lisp/font-lock.el | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index ab3f84f18be..d96058ba12b 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -753,12 +753,24 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types', | |||
| 753 | ;; Otherwise if Font Lock mode is on, set or add the keywords now. | 753 | ;; Otherwise if Font Lock mode is on, set or add the keywords now. |
| 754 | (if (eq append 'set) | 754 | (if (eq append 'set) |
| 755 | (setq font-lock-keywords keywords) | 755 | (setq font-lock-keywords keywords) |
| 756 | (font-lock-remove-keywords keywords) | ||
| 756 | (let ((old (if (eq (car-safe font-lock-keywords) t) | 757 | (let ((old (if (eq (car-safe font-lock-keywords) t) |
| 757 | (cdr font-lock-keywords) | 758 | (cdr font-lock-keywords) |
| 758 | font-lock-keywords))) | 759 | font-lock-keywords))) |
| 759 | (setq font-lock-keywords (if append | 760 | (setq font-lock-keywords (if append |
| 760 | (append old keywords) | 761 | (append old keywords) |
| 761 | (append keywords old)))))))) | 762 | (append keywords old)))))))) |
| 763 | |||
| 764 | ;;;###autoload | ||
| 765 | (defun font-lock-remove-keywords (keywords) | ||
| 766 | "Remove highlighting KEYWORDS from the current buffer." | ||
| 767 | (setq font-lock-keywords (copy-list font-lock-keywords)) | ||
| 768 | (dolist (keyword keywords) | ||
| 769 | (setq font-lock-keywords | ||
| 770 | (delete keyword | ||
| 771 | (delete (font-lock-compile-keyword keyword) | ||
| 772 | font-lock-keywords))))) | ||
| 773 | |||
| 762 | 774 | ||
| 763 | ;;; Global Font Lock mode. | 775 | ;;; Global Font Lock mode. |
| 764 | 776 | ||
| @@ -1096,8 +1108,15 @@ The value of this variable is used when Font Lock mode is turned on." | |||
| 1096 | ;; check to see if we should expand the beg/end area for | 1108 | ;; check to see if we should expand the beg/end area for |
| 1097 | ;; proper multiline matches | 1109 | ;; proper multiline matches |
| 1098 | (setq beg (if (get-text-property beg 'font-lock-multiline) | 1110 | (setq beg (if (get-text-property beg 'font-lock-multiline) |
| 1111 | ;; if the text-property is non-nil, (1+ beg) | ||
| 1112 | ;; is valid. We need to use (1+ beg) for the | ||
| 1113 | ;; case where (get-text-property (1- beg)) is nil | ||
| 1114 | ;; in which case we want to keep BEG but | ||
| 1115 | ;; previous-single-property-change will return | ||
| 1116 | ;; the previous change (if any) rather than | ||
| 1117 | ;; the one at BEG. | ||
| 1099 | (or (previous-single-property-change | 1118 | (or (previous-single-property-change |
| 1100 | beg 'font-lock-multiline) | 1119 | (1+ beg) 'font-lock-multiline) |
| 1101 | (point-min)) | 1120 | (point-min)) |
| 1102 | beg)) | 1121 | beg)) |
| 1103 | (setq end (or (text-property-any end (point-max) | 1122 | (setq end (or (text-property-any end (point-max) |