65: What are hilit19 and font-lock modes, what is the difference between
them, and how do I customize them?
Hilit19 and font-lock are two minor modes that syntactically highlight
Emacs buffers using colors and fonts of your choosing. This is
especially useful when editing code, since strings can be in one face,
comments a second color, and function definitions a third. Both packages
come with Emacs 19.
Hilit19 is slower than font-lock mode, but is easier to customize and has
regexps for more major modes. To invoke hilit19 automatically whenever
you start Emacs, include the following Lisp forms (stolen from the
documentation at the top of hilit19.el, which should be in your lisp
directory) in your .emacs file:
(cond (window-system
(setq hilit-mode-enable-list '(not text-mode)
hilit-background-mode 'light
hilit-inhibit-hooks nil
hilit-inhibit-rebinding nil)
(require 'hilit19)))
Note that hilit-background-mode should be set to 'dark (and not 'light)
if your Emacs window has a dark background.
Changing the default hilit19 face specifications requires the use of
hilit-translate. See the comments at the top of hilit19.el for some
examples of how to use hilit-translate, as well as for some basic
instructions.
Font-lock is faster than hilit19, but comes with fewer predefined regexps
and supports fewer major modes. To enable font-lock for a particular
mode, you will need to use the hook for that mode. For example, to turn
on font-lock mode every time you load an Emacs Lisp file, add the
following to your .emacs file:
(add-hook 'emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
Customization of font-lock mode is done by setting the variables
font-lock-comment-face, font-lock-string-face, font-lock-doc-string-face,
and font-lock-function-name-face. You may define new reserved words by
modifying the variable font-lock-keywords.
If you want to use hilit19 for some modes and font-lock for others, you
can use the variable hilit-mode-enable-list. See the documentation for
that variable (using M-x describe-variable) for instructions on how to
set it.
You might also want to look at Simon Marshall's face-lock package, which
handles fontification and provides an easier interface to font-lock. You
can get face-lock from the Emacs Lisp Archive; see question 87.