From: Karl Heuer Date: Tue, 1 Feb 1994 01:32:48 +0000 (+0000) Subject: (font-lock-mode): Use the new hooks to get proper behavior on a revert. X-Git-Tag: emacs-19.34~10134 X-Git-Url: https://code.delx.au/gnu-emacs/commitdiff_plain/7daa8d6b1c2c0bf611ab977240e514661fbef214 (font-lock-mode): Use the new hooks to get proper behavior on a revert. --- diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 9ce1ed1e8b..d0c042d39d 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -365,17 +365,32 @@ can use \\[font-lock-fontify-buffer]." (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: