Go to the first, previous, next, last section, table of contents.


Lazy Lock Mode

To make Font Lock mode faster for large buffers, you can use Lazy Lock mode to reduce the amount of text that is fontified. In Lazy Lock mode, buffer fontification is demand-driven; it happens to portions of the buffer that are about to be displayed. And fontification of your changes is deferred; it happens only when Emacs has been idle for a certain short period of time.

The command M-x lazy-lock-mode turns Lazy Lock mode on or off, according to the argument (with no argument, it toggles). You can also arrange to enable Lazy Lock mode whenever you use Font Lock mode, like this:

(setq font-lock-support-mode 'lazy-lock-mode)

It is not worth avoiding buffer fontification for small buffers. Therefore, the variable lazy-lock-minimum-size specifies a minimum buffer size for demand-driven buffer fontification. Buffers smaller than that are fontified all at once, as in plain Font Lock mode.

When you alter the buffer, Lazy Lock mode defers fontification of the text you changed. The variable lazy-lock-defer-time specifies how many seconds Emacs must be idle before it starts fontifying your changes. If the value is 0, then changes are fontified immediately, as in plain Font Lock mode.

Lazy Lock mode normally fontifies newly visible portions of the buffer before they are first displayed. However, if the value of lazy-lock-defer-on-scrolling is non-nil, newly visible text is fontified only when Emacs is idle for lazy-lock-defer-time seconds.

In some modes, including C mode and Emacs Lisp mode, changes in one line's contents can alter the context for subsequent lines, and thus change how they ought to be fontified. Ordinarily, you must type M-g M-g to refontify the subsequent lines. However, if you set the variable lazy-lock-defer-contextually to non-nil, Lazy Lock mode does this automatically, after lazy-lock-defer-time seconds.

When Emacs is idle for a long time, Lazy Lock fontifies additional portions of the buffer, not yet displayed, in case you will display them later. This is called stealth fontification.

The variable lazy-lock-stealth-time specifies how many seconds Emacs has to be idle before stealth fontification starts. A value of nil means no stealth fontification. The variables lazy-lock-stealth-lines and lazy-lock-stealth-verbose specify the granularity and verbosity of stealth fontification.


Go to the first, previous, next, last section, table of contents.