5.43 How do I turn on syntax highlighting?

font-lock-mode is the standard way to have Emacs perform syntax highlighting in the current buffer. It is enabled by default.

With font-lock-mode turned on, different types of text will appear in different colors. For instance, in a programming mode, variables will appear in one face, keywords in a second, and comments in a third.

To turn font-lock-mode off within an existing buffer, use M-x font-lock-mode RET.

Highlighting a buffer with font-lock-mode can take quite a while, and cause an annoying delay in display, so several features exist to work around this.

Turning on font-lock-mode automatically activates Just-In-Time fontification provided by jit-lock-mode. jit-lock-mode defers the fontification of portions of buffer until you actually need to see them, and can also fontify while Emacs is idle. This makes display of the visible portion of a buffer almost instantaneous. For details about customizing jit-lock-mode, type C-h f jit-lock-mode RET.

Different levels of decoration are available, from slight to gaudy. More decoration means you need to wait more time for a buffer to be fontified (or a faster machine). To control how decorated your buffers should become, set the value of font-lock-maximum-decoration in your init file (see How do I set up an init file properly?), with a nil value indicating default (usually minimum) decoration, and a t value indicating the maximum decoration. For the gaudiest possible look, then, include the line

(setq font-lock-maximum-decoration t)

in your init file. You can also set this variable such that different modes are highlighted in a different ways; for more information, see the documentation for font-lock-maximum-decoration with C-h v (or M-x describe-variable RET).

Also see the documentation for the function font-lock-mode, available by typing C-h f font-lock-mode (M-x describe-function RET font-lock-mode RET).

To print buffers with the faces (i.e., colors and fonts) intact, use M-x ps-print-buffer-with-faces or M-x ps-print-region-with-faces. You will need a way to send text to a PostScript printer, or a PostScript interpreter such as Ghostscript; consult the documentation of the variables ps-printer-name, ps-lpr-command, and ps-lpr-switches for more details.