[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

23.6.1 Font Lock Basics

There are several variables that control how Font Lock mode highlights text. But major modes should not set any of these variables directly. Instead, they should set font-lock-defaults as a buffer-local variable. The value assigned to this variable is used, if and when Font Lock mode is enabled, to set all the other variables.

Variable: font-lock-defaults

This variable is set by major modes, as a buffer-local variable, to specify how to fontify text in that mode. It automatically becomes buffer-local when you set it. If its value is nil, Font-Lock mode does no highlighting, and you can use the ‘Faces’ menu (under ‘Edit’ and then ‘Text Properties’ in the menu bar) to assign faces explicitly to text in the buffer.

If non-nil, the value should look like this:

 
(keywords [keywords-only [case-fold
 [syntax-alist [syntax-begin other-vars…]]]])

The first element, keywords, indirectly specifies the value of font-lock-keywords which directs search-based fontification. It can be a symbol, a variable or a function whose value is the list to use for font-lock-keywords. It can also be a list of several such symbols, one for each possible level of fontification. The first symbol specifies how to do level 1 fontification, the second symbol how to do level 2, and so on. Voir la section Levels of Font Lock.

The second element, keywords-only, specifies the value of the variable font-lock-keywords-only. If this is omitted or nil, syntactic fontification (of strings and comments) is also performed. If this is non-nil, such fontification is not performed. Voir la section Syntactic Font Lock.

The third element, case-fold, specifies the value of font-lock-keywords-case-fold-search. If it is non-nil, Font Lock mode ignores case when searching as directed by font-lock-keywords.

If the fourth element, syntax-alist, is non-nil, it should be a list of cons cells of the form (char-or-string . string). These are used to set up a syntax table for syntactic fontification (voir la section Syntax Table Functions). The resulting syntax table is stored in font-lock-syntax-table.

The fifth element, syntax-begin, specifies the value of font-lock-beginning-of-syntax-function. We recommend setting this variable to nil and using syntax-begin-function instead.

All the remaining elements (if any) are collectively called other-vars. Each of these elements should have the form (variable . value)—which means, make variable buffer-local and then set it to value. You can use these other-vars to set other variables that affect fontification, aside from those you can control with the first five elements. Voir la section Other Font Lock Variables.

If your mode fontifies text explicitly by adding font-lock-face properties, it can specify (nil t) for font-lock-defaults to turn off all automatic fontification. However, this is not required; it is possible to fontify some things using font-lock-face properties and set up automatic fontification for other parts of the text.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.