Mercurial > emacs
changeset 5717:24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 01 Feb 1994 01:32:48 +0000 |
parents | 82588f97d478 |
children | 3548110b4957 |
files | lisp/font-lock.el |
diffstat | 1 files changed, 18 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/font-lock.el Tue Feb 01 01:31:37 1994 +0000 +++ b/lisp/font-lock.el Tue Feb 01 01:32:48 1994 +0000 @@ -365,17 +365,32 @@ (set (make-local-variable 'font-lock-mode) on-p) (cond (on-p (font-lock-set-defaults) + (make-local-variable 'before-revert-hook) (make-local-variable 'after-revert-hook) - ;;if buffer is reverted, must repeat fontification. - (setq after-revert-hook 'font-lock-fontify-buffer) + ;; If buffer is reverted, must clean up the state. + (add-hook 'before-revert-hook 'font-lock-revert-setup) + (add-hook 'after-revert-hook 'font-lock-revert-cleanup) (run-hooks 'font-lock-mode-hook) (or font-lock-fontified (font-lock-fontify-buffer))) (font-lock-fontified (setq font-lock-fontified nil) - (setq after-revert-hook nil) + (remove-hook 'before-revert-hook 'font-lock-revert-setup) + (remove-hook 'after-revert-hook 'font-lock-revert-cleanup) (font-lock-unfontify-region (point-min) (point-max)))) (force-mode-line-update))) +;; If the buffer is about to be reverted, it won't be fontified. +(defun font-lock-revert-setup () + (setq font-lock-fontified nil)) + +;; If the buffer has just been reverted, we might not even be in font-lock +;; mode anymore, and if we are, the buffer may or may not have already been +;; refontified. Refontify here if it looks like we need to. +(defun font-lock-revert-cleanup () + (and font-lock-mode + (not font-lock-fontified) + (font-lock-mode 1))) + (defun font-lock-fontify-buffer () "Fontify the current buffer the way `font-lock-mode' would: