Next: Multiline Font Lock, Previous: Faces for Font Lock, Up: Font Lock Mode
Syntactic fontification uses a syntax table (see Syntax Tables) to
find and highlight syntactically relevant text. If enabled, it runs
prior to search-based fontification. The variable
font-lock-syntactic-face-function
, documented below, determines
which syntactic constructs to highlight. There are several variables
that affect syntactic fontification; you should set them by means of
font-lock-defaults
(see Font Lock Basics).
Whenever Font Lock mode performs syntactic fontification on a stretch
of text, it first calls the function specified by
syntax-propertize-function
. Major modes can use this to apply
syntax-table
text properties to override the buffer's syntax
table in special cases. See Syntax Properties.
If the value of this variable is non-
nil
, Font Lock does not do syntactic fontification, only search-based fontification based onfont-lock-keywords
. It is normally set by Font Lock mode based on the keywords-only element infont-lock-defaults
.
This variable holds the syntax table to use for fontification of comments and strings. It is normally set by Font Lock mode based on the syntax-alist element in
font-lock-defaults
. If this value isnil
, syntactic fontification uses the buffer's syntax table (the value returned by the functionsyntax-table
; see Syntax Table Functions).
If this variable is non-
nil
, it should be a function to move point back to a position that is syntactically at “top level” and outside of strings or comments. The value is normally set through an other-vars element infont-lock-defaults
. If it isnil
, Font Lock usessyntax-begin-function
to move back outside of any comment, string, or sexp (see Position Parse).This variable is semi-obsolete; we usually recommend setting
syntax-begin-function
instead. One of its uses is to tune the behavior of syntactic fontification, e.g., to ensure that different kinds of strings or comments are highlighted differently.The specified function is called with no arguments. It should leave point at the beginning of any enclosing syntactic block. Typical values are
beginning-of-line
(used when the start of the line is known to be outside a syntactic block), orbeginning-of-defun
for programming modes, orbackward-paragraph
for textual modes.
If this variable is non-
nil
, it should be a function to determine which face to use for a given syntactic element (a string or a comment). The value is normally set through an other-vars element infont-lock-defaults
.The function is called with one argument, the parse state at point returned by
parse-partial-sexp
, and should return a face. The default value returnsfont-lock-comment-face
for comments andfont-lock-string-face
for strings (see Faces for Font Lock).