;;; Code:
+(defvar font-lock-maximum-size)
+(defvar font-lock-verbose)
+
;; This variable is used by mode packages that support Font Lock mode by
;; defining their own keywords to use for `font-lock-keywords'. (The mode
;; command should make it buffer-local and set it to provide the set up.)
Other variables include that for syntactic keyword fontification,
`font-lock-syntactic-keywords'
-and those for buffer-specialised fontification functions,
+and those for buffer-specialized fontification functions,
`font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
`font-lock-fontify-region-function', `font-lock-unfontify-region-function',
`font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")
;; batch job) or if the buffer is invisible (the name starts with a space).
(when (or noninteractive (eq (aref (buffer-name) 0) ?\ ))
(setq font-lock-mode nil))
- (funcall font-lock-function font-lock-mode))
-
-(defun font-lock-default-function (font-lock-mode)
+ (funcall font-lock-function font-lock-mode)
+ ;; Arrange to unfontify this buffer if we change major mode later.
+ (if font-lock-mode
+ (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t)
+ (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)))
+
+;; Get rid of fontification for the old major mode.
+;; We do this when changing major modes.
+(defun font-lock-change-mode ()
+ (font-lock-mode -1))
+
+(defun font-lock-defontify ()
+ "Clear out all `font-lock-face' properties in current buffer.
+A major mode that uses `font-lock-face' properties should put
+this function onto `change-major-mode-hook'."
+ (let ((modp (buffer-modified-p))
+ (inhibit-read-only t))
+ (save-restriction
+ (widen)
+ (remove-list-of-text-properties (point-min) (point-max)
+ '(font-lock-face)))
+ (set-buffer-modified-p modp)))
+
+(defun font-lock-default-function (mode)
;; Turn on Font Lock mode.
- (when font-lock-mode
+ (when mode
(font-lock-set-defaults)
(set (make-local-variable 'char-property-alias-alist)
(copy-tree char-property-alias-alist))
(message "Fontifying %s...buffer size greater than font-lock-maximum-size"
(buffer-name)))))))
;; Turn off Font Lock mode.
- (unless font-lock-mode
+ (unless mode
;; Remove `font-lock-face' as an alias for the `face' property.
(set (make-local-variable 'char-property-alias-alist)
(copy-tree char-property-alias-alist))