Using Emacs with X Fonts and Colors

Emacs under X can display text in multiple fixed-width fonts. It doesn’t yet handle proportional-spacing fonts well, although future releases are expected to address that issue. Emacs under X also displays text in as many combinations of foreground and background colors as your X server will support.

Holding down the SHIFT key while clicking the left button takes you to a menu of fonts. Selecting one of these instantly changes the Emacs font for the current frame and redisplays the frame. This is an easy way to experiment with different fonts to see how well they trade screen space for readability on your display.

To see the range of colors available, select your Edit menu from the menu bar, go to the Text Properties submenu, then select the Display Colors item. This item won’t show you all possible foreground/background color combinations (there are far too many for that, typically hundreds if not thousands), but it will show you what each color looks like as both text foreground and background.

Automatic Highlighting and Coloring

The easiest way to use fonts and colors is to load the LISP package font-lock.el (included with the Emacs distribution). This mode tries to highlight interesting features of your text buffers using color and different faces. As an example, try picking out comments in C and LISP buffers, and painting them in a color that contrasts with the basic black of the code.

;; Turn on font lock mode every time Emacs initializes ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.