Commit 7daa8d6b authored by Karl Heuer's avatar Karl Heuer
Browse files

(font-lock-mode): Use the new hooks to get proper behavior on a revert.

parent 4fbf62ee
......@@ -365,17 +365,32 @@ can use \\[font-lock-fontify-buffer]."
(set (make-local-variable 'font-lock-mode) on-p)
(cond (on-p
(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)))
(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))))
;; 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:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment