24.6.4 Other Font Lock Variables

This section describes additional variables that a major mode can set by means of other-vars in font-lock-defaults (see Font Lock Basics).

Variable: font-lock-mark-block-function

If this variable is non-nil, it should be a function that is called with no arguments, to choose an enclosing range of text for refontification for the command M-x font-lock-fontify-block.

The function should report its choice by placing the region around it. A good choice is a range of text large enough to give proper results, but not too large so that refontification becomes slow. Typical values are mark-defun for programming modes or mark-paragraph for textual modes.

Variable: font-lock-extra-managed-props

This variable specifies additional properties (other than font-lock-face) that are being managed by Font Lock mode. It is used by font-lock-default-unfontify-region, which normally only manages the font-lock-face property. If you want Font Lock to manage other properties as well, you must specify them in a facespec in font-lock-keywords as well as add them to this list. See Search-based Fontification.

Variable: font-lock-fontify-buffer-function

Function to use for fontifying the buffer. The default value is font-lock-default-fontify-buffer.

Variable: font-lock-unfontify-buffer-function

Function to use for unfontifying the buffer. This is used when turning off Font Lock mode. The default value is font-lock-default-unfontify-buffer.

Variable: font-lock-fontify-region-function

Function to use for fontifying a region. It should take two arguments, the beginning and end of the region, and an optional third argument verbose. If verbose is non-nil, the function should print status messages. The default value is font-lock-default-fontify-region.

Variable: font-lock-unfontify-region-function

Function to use for unfontifying a region. It should take two arguments, the beginning and end of the region. The default value is font-lock-default-unfontify-region.

Variable: font-lock-flush-function

Function to use for declaring that a region’s fontification is out of date. It takes two arguments, the beginning and end of the region. The default value of this variable is font-lock-after-change-function.

Variable: font-lock-ensure-function

Function to use for making sure a region of the current buffer has been fontified. It is called with two arguments, the beginning and end of the region. The default value of this variable is a function that calls font-lock-default-fontify-buffer if the buffer is not fontified; the effect is to make sure the entire accessible portion of the buffer is fontified.

Function: jit-lock-register function &optional contextual

This function tells Font Lock mode to run the Lisp function function any time it has to fontify or refontify part of the current buffer. It calls function before calling the default fontification functions, and gives it two arguments, start and end, which specify the region to be fontified or refontified. If function performs fontifications, it can return a list of the form (jit-lock-bounds beg . end), to indicate the bounds of the region it actually fontified; Just-In-Time (a.k.a. “JIT”) font-lock will use this information to optimize subsequent redisplay cycles and regions of buffer text it will pass to future calls to function.

The optional argument contextual, if non-nil, forces Font Lock mode to always refontify a syntactically relevant part of the buffer, and not just the modified lines. This argument can usually be omitted.

When Font Lock is activated in a buffer, it calls this function with a non-nil value of contextual if the value of font-lock-keywords-only (see Syntactic Font Lock) is nil.

Function: jit-lock-unregister function

If function was previously registered as a fontification function using jit-lock-register, this function unregisters it.

Command: jit-lock-debug-mode &optional arg

This is a minor mode whose purpose is to help in debugging code that is run by JIT font-lock. When this mode is enabled, most of the code that JIT font-lock normally runs during redisplay cycles, where Lisp errors are suppressed, is instead run by a timer. Thus, this mode allows using debugging aids such as debug-on-error (see Entering the Debugger on an Error) and Edebug (see Edebug) for finding and fixing problems in font-lock code and any other code run by JIT font-lock. Another command that could be useful when developing and debugging font-lock is font-lock-debug-fontify, see Font Lock Basics.