4

I want to understand the fields in font-lock-defaults. The documentation reads

Defaults for Font Lock mode specified by the major mode. Defaults should be of the form:

(KEYWORDS [KEYWORDS-ONLY [CASE-FOLD [SYNTAX-ALIST ...]]])

KEYWORDS may be a symbol (a variable or function whose value is the keords to use for fontification) or a list of symbols (specifying different levels of fontification).

If KEYWORDS-ONLY is non-nil, syntactic fontification (strings and comments) is not performed.

If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying.

If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form (CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for keyword and syntactic fontification (see ‘modify-syntax-entry’).

When I look at font-lock-defaults for Python and Elisp mode, I see the following values.

Question: What do the four nil's mean in the Python and Elisp modes? I am not understanding how to match the elements of the list below to the documentation.

  • Python
((python-font-lock-keywords-level-1
  python-font-lock-keywords-level-1 
  python-font-lock-keywords-level-2
  python-font-lock-keywords-maximum-decoration)
 nil nil nil nil
 (font-lock-syntactic-face-function . python-font-lock-syntactic-face-function))
  • Elisp
((lisp-el-font-lock-keywords
  lisp-el-font-lock-keywords-1
  lisp-el-font-lock-keywords-2)
 nil nil nil nil
 (font-lock-mark-block-function . mark-defun)
 (font-lock-extra-managed-props help-echo)
 (font-lock-syntactic-face-function . lisp-font-lock-syntactic-face-function))
0

1 Answer 1

3

When in doubt, look at the source code. This variable is defined in font-core.el, so it is a good bet that the code which uses the variable is also in that file. A quick search turns up the function font-lock-set-defaults in font-lock.el, which grovels through the various things stored in this variable and does something with each one. By reading that code, including some comments in it, we can deduce what everything is for.

nth docstring variable
0 KEYWORDS keywords
1 KEYWORDS-ONLY font-lock-keywords-only
2 CASE-FOLD font-lock-keywords-case-fold-search
3 SYNTAX-ALIST font-lock-syntax-table
4 font-lock-beginning-of-syntax-function
5… Further item elements are alists of the form… alist

So why isn’t font-lock-beginning-of-syntax-function mentioned in the docstring? Well, there is a comment that explains:

;; (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.

The values of this variable for various modes simply predates the change that removed the font-lock-beginning-of-syntax-function variable, and they just didn’t bother to change every single mode that sets this variable (because that’s a lot of modes). Instead they made the code check to see if it’s there and skip over it if it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.