Variable: font-lock-defaults

font-lock-defaults is a buffer-local variable defined in font-core.el.gz.

Documentation

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 keywords 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).

These item elements are used by Font Lock mode to set the variables font-lock-keywords, font-lock-keywords-only, font-lock-keywords-case-fold-search, font-lock-syntax-table.

Further item elements are alists of the form (VARIABLE . VALUE) and are in no particular order. Each VARIABLE is made buffer-local before set to VALUE.

Currently, appropriate variables include font-lock-mark-block-function. If this is non-nil, it should be a function with no args used to mark any enclosing block of text, for fontification via M-x font-lock-fontify-block (font-lock-fontify-block). Typical values are mark-defun for programming modes or mark-paragraph for textual modes (i.e., the mode-dependent function is known to put point and mark around a text block relevant to that mode).

Other variables include that for syntactic keyword fontification, font-lock-syntactic-keywords 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.

View in manual

Probably introduced at or before Emacs version 19.29.

Source Code

;; Defined in /usr/src/emacs/lisp/font-core.el.gz
;;; font-core.el --- Core interface to font-lock  -*- lexical-binding: t; -*-

;; Copyright (C) 1992-2025 Free Software Foundation, Inc.

;; Maintainer: emacs-devel@gnu.org
;; Keywords: languages, faces
;; Package: emacs

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

;; 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.)
(defvar-local font-lock-defaults nil
  "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 keywords
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').

These item elements are used by Font Lock mode to set the variables
`font-lock-keywords', `font-lock-keywords-only',
`font-lock-keywords-case-fold-search', `font-lock-syntax-table'.

Further item elements are alists of the form (VARIABLE . VALUE) and are in no
particular order.  Each VARIABLE is made buffer-local before set to VALUE.

Currently, appropriate variables include `font-lock-mark-block-function'.
If this is non-nil, it should be a function with no args used to mark any
enclosing block of text, for fontification via \\[font-lock-fontify-block].
Typical values are `mark-defun' for programming modes or `mark-paragraph' for
textual modes (i.e., the mode-dependent function is known to put point and mark
around a text block relevant to that mode).

Other variables include that for syntactic keyword fontification,
`font-lock-syntactic-keywords' 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'.")