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

Using Multiple Typefaces

When using Emacs with X, you can set up multiple styles of displaying characters. The aspects of style that you can control are the type font, the foreground color, the background color, and whether to underline. Emacs 19.29 does not support faces on MS-DOS, but future versions may support them partially (see section MS-DOS Issues).

The way you control display style is by defining named faces. Each face can specify a type font, a foreground color, a background color, and an underline flag; but it does not have to specify all of them.

The style of display used for a given character in the text is determined by combining several faces. Any aspect of the display style that isn't specified by overlays or text properties comes from the frame itself.

Enriched mode, the mode for editing formatted text, includes several commands and menus for specifying faces. See section Faces in Formatted Text, for how to specify the font for text in the buffer. See section Colors in Formatted Text, for how to specify the foreground and background color.

To see what faces are currently defined, and what they look like, type M-x list-faces-display. It's possible for a given face to look different in different frames; this command shows the appearance in the frame in which you type it. Here's a list of the standardly defined faces:

default
This face is used for ordinary text that doesn't specify any other face.
modeline
This face is used for mode lines. By default, it's set up as the inverse of the default face. See section Variables Controlling Display.
highlight
This face is used for highlighting portions of text, in various modes.
region
This face is used for displaying a selected region (when Transient Mark mode is enabled--see below).
secondary-selection
This face is used for displaying a secondary selection (see section Secondary Selection).
bold
This face uses a bold variant of the default font, if it has one.
italic
This face uses an italic variant of the default font, if it has one.
bold-italic
This face uses a bold italic variant of the default font, if it has one.
underline
This face underlines text.

When Transient Mark mode is enabled, the text of the region is highlighted when the mark is active. This uses the face named region; you can control the style of highlighting by changing the style of this face (see section Modifying Faces). See section Transient Mark Mode, for more information about Transient Mark mode and activation and deactivation of the mark.

One easy way to use faces is to turn on Font-Lock mode. This minor mode, which is always local to a particular buffer, arranges to choose faces according to the syntax of the text you are editing. It can recognize comments and strings in most languages; in several languages, it can also recognize and properly highlight various other important constructs--for example, names of functions being defined.

Font-Lock mode is a minor mode. The command M-x font-lock-mode turns the mode on or off. The function turn-on-font-lock unconditionally enables Font-Lock mode. This is useful in mode-hook functions. For example, to enable Font-Lock mode whenever you edit a C file, you can do this:

(add-hook 'c-mode-hook 'turn-on-font-lock)

To get the full benefit of Font-Lock mode, you need to choose a default font which has bold, italic, and bold-italic variants; or else you need to have a color or grayscale screen. The variable font-lock-display-type specifies whether Font-Lock mode should use font styles, colors, or shades of gray to distinguish the various kinds of text. Emacs chooses the default value according to the characteristics of your display.


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