Function: font-lock-set-defaults
font-lock-set-defaults is a byte-compiled function defined in
font-lock.el.gz.
Signature
(font-lock-set-defaults)
Documentation
Set fontification defaults appropriately for this mode.
Sets various variables using font-lock-defaults and
font-lock-maximum-decoration.
Source Code
;; Defined in /usr/src/emacs/lisp/font-lock.el.gz
(defun font-lock-set-defaults ()
"Set fontification defaults appropriately for this mode.
Sets various variables using `font-lock-defaults' and
`font-lock-maximum-decoration'."
;; Set fontification defaults if not previously set for correct major mode.
(when (or (not font-lock-set-defaults)
(not font-lock-major-mode)
(not (derived-mode-p font-lock-major-mode)))
(setq font-lock-major-mode major-mode)
(setq font-lock-set-defaults t)
(let* ((defaults font-lock-defaults)
(keywords
(font-lock-choose-keywords (nth 0 defaults)
(font-lock-value-in-major-mode font-lock-maximum-decoration)))
(local (cdr (assq major-mode font-lock-keywords-alist)))
(removed-keywords
(cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
;; Syntactic fontification?
(setq-local font-lock-keywords-only (nth 1 defaults))
;; Case fold during regexp fontification?
(setq-local font-lock-keywords-case-fold-search (nth 2 defaults))
;; Syntax table for regexp and syntactic fontification?
(kill-local-variable 'font-lock--syntax-table-affects-ppss)
(if (null (nth 3 defaults))
(setq-local font-lock-syntax-table nil)
(setq-local font-lock-syntax-table (copy-syntax-table (syntax-table)))
(dolist (selem (nth 3 defaults))
;; The character to modify may be a single CHAR or a STRING.
(let ((syntax (cdr selem)))
(dolist (char (if (numberp (car selem))
(list (car selem))
(mapcar #'identity (car selem))))
(let ((old-syntax (aref font-lock-syntax-table char)))
(modify-syntax-entry char syntax font-lock-syntax-table)
(let ((new-syntax (aref font-lock-syntax-table char)))
(unless (and (equal (cdr old-syntax) (cdr new-syntax))
;; Changes within the w/_/./' subset don't
;; affect `syntax-ppss'.
(memq (logand (car old-syntax) 255) '(1 2 3 6))
(memq (logand (car new-syntax) 255) '(1 2 3 6))
;; Check changes to the syntax flags.
(equal (ash (car old-syntax) -8)
(ash (car new-syntax) -8)))
(setq font-lock--syntax-table-affects-ppss t))))))))
;; (nth 4 defaults) used to hold `font-lock-beginning-of-syntax-function',
;; but that was removed in 25.1, so if it's a cons cell, we assume that
;; it's part of the variable alist.
;; Variable alist?
(dolist (x (nthcdr (if (consp (nth 4 defaults)) 4 5) defaults))
(set (make-local-variable (car x)) (cdr x)))
;; Set up `font-lock-keywords' last because its value might depend
;; on other settings.
(setq-local font-lock-keywords
(font-lock-eval-keywords keywords))
;; Local fontification?
(while local
(font-lock-add-keywords nil (car (car local)) (cdr (car local)))
(setq local (cdr local)))
(when removed-keywords
(font-lock-remove-keywords nil removed-keywords))
;; Now compile the keywords.
(unless (eq (car font-lock-keywords) t)
(setq font-lock-keywords
(font-lock-compile-keywords font-lock-keywords))))
(font-lock-flush)))