diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 1999-12-07 06:31:57 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 1999-12-07 06:31:57 +0000 |
commit | 3708dfe933b3c567c39ee5619b22bbb4c128aca1 (patch) | |
tree | 12f89d1b59e752b07529fc8d510377ce599a939f /lisp/font-lock.el | |
parent | 707ad06002b6d134339b1df083fad19ba274d41d (diff) | |
download | emacs-3708dfe933b3c567c39ee5619b22bbb4c128aca1.tar.gz |
(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.
Diffstat (limited to 'lisp/font-lock.el')
-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', ;; Otherwise if Font Lock mode is on, set or add the keywords now. (if (eq append 'set) (setq font-lock-keywords keywords) + (font-lock-remove-keywords keywords) (let ((old (if (eq (car-safe font-lock-keywords) t) (cdr font-lock-keywords) font-lock-keywords))) (setq font-lock-keywords (if append (append old keywords) (append keywords old)))))))) + +;;;###autoload +(defun font-lock-remove-keywords (keywords) + "Remove highlighting KEYWORDS from the current buffer." + (setq font-lock-keywords (copy-list font-lock-keywords)) + (dolist (keyword keywords) + (setq font-lock-keywords + (delete keyword + (delete (font-lock-compile-keyword keyword) + font-lock-keywords))))) + ;;; Global Font Lock mode. @@ -1096,8 +1108,15 @@ The value of this variable is used when Font Lock mode is turned on." ;; check to see if we should expand the beg/end area for ;; proper multiline matches (setq beg (if (get-text-property beg 'font-lock-multiline) + ;; if the text-property is non-nil, (1+ beg) + ;; is valid. We need to use (1+ beg) for the + ;; case where (get-text-property (1- beg)) is nil + ;; in which case we want to keep BEG but + ;; previous-single-property-change will return + ;; the previous change (if any) rather than + ;; the one at BEG. (or (previous-single-property-change - beg 'font-lock-multiline) + (1+ beg) 'font-lock-multiline) (point-min)) beg)) (setq end (or (text-property-any end (point-max) |