The default Emacs color scheme is affectionately known as “angry fruit salad”.
Click on ‘Set Default Font’ in the ‘Options’ menu. To save this for future sessions, click on ‘Save Options’ in the ‘Options’ menu.
“DejaVu Sans Mono” is a good choice (also known as “Bitstream Vera Sans Mono”, or “Menlo” on OS X 10.6+). Do choose a fixed-width font, even if you like proportional fonts for programming. We’ll cover Emacs’s handling of proportional fonts later.
There is a known bug on
OS X that prevents “Save Options” from saving changes to the default font. OS X
users will have to use the
customize-face mechanism I explain below,
default as the face name.
Font Lock mode is the minor mode responsible for syntax highlighting. You can read up on font-lock mode if you want to figure out how Emacs decides what is a comment or a keyword or a variable, or how to add your own keywords.
But to merely change the colors:
Figure out the name of the face you want to change:
to the face at point) or
modify-face will prompt you for a face and for each attribute to change.
Leave attributes as “unspecified” (the default) to inherit from the default
face. When it comes to the foreground and background colors, you can use the
predefined colors shown by tab-completion, or you can specify RGB hex values
customize-face brings up the “easy customization” interface I warned you
against in the previous chapter. Click the
State button and select
for Future Sessions. (You can make changes here too, but I prefer
modify-face because it gives you tab-completion on the possible values for
Now let’s figure out how to bypass the “easy customization” interface:
Visit your init file to see what “easy customization” added. If you already
had the file open, you may need
revert-buffer to see the latest changes.
You could configure the remaining font-lock faces by adding arguments to the
custom-set-faces form, but they might be overwritten if you use the easy
customization framework in future. Inspired by the name
searched for functions beginning with
set-face and found
The above settings produce a very conservative dark-on-white color scheme. I like it because in many languages it highlights variable and function definitions but not their uses.
For all the face attribute names see “Face Attributes”
in the Emacs Lisp manual. As to elisp syntax, keyword symbols like
:weight are constants (that evaluate to themselves so you
don’t have to quote them).
While we’re on colors, let’s add some helpful coloring to
we came across earlier, in the section on the
vc version control
eval-after-load does what it says: The first time
diff-mode is loaded,
evaluate the following form. Emacs tends not to load every elisp package on
startup, but waits until you actually use
diff-mode to load it.
If you used
(set-face-foreground 'diff-added ...) directly in your init file,
you would get the error “invalid face diff-added”. You could explicitly load
require) in your init file, but that would increase
Emacs’s startup time—ever so slightly—every time you run Emacs in the
terminal for a quick job that won’t even use
eval-after-load takes a single form to evaluate, but we want to make two
function calls, so we wrap them in
progn which merely evaluates a bunch of
forms sequentially. We quote it so that it doesn’t get evaluated right now,
before even being passed to
The first argument to
eval-after-load has to match the name that the package
provides (this usually matches the name of the command to enable the mode,
but to double-check:
C-h f diff-mode, follow the link to
and find the
provide form near the bottom).
Note: This section and the next, which deal with the
were written for Emacs 23.
color-theme is obsolete in Emacs 24, so I need
to find a better example for installing third-party packages.
Maybe you already have a favourite color theme, like Zenburn or Solarized. There are Emacs implementations
(Zenburn, Solarized) built on top of the
color-theme minor mode.
is a third-party package; it doesn’t come with Emacs.
Note that Emacs 24 provides a built-in mechanism for defining multiple color
themes. Nevertheless, I’ll walk you through the process of installing
third-party packages using
color-theme and the Solarized theme as examples.
Emacs 24 also comes with a package management system, so—as long as the package’s author has taken advantage of the new mechanism—the manual installation procedure described below will not be necessary either.
I’ll assume that you are keeping your
~/.emacs.d under version control using
color-theme’s installation instructions recommend using your package manager
apt-get install emacs-goodies-el or
port install color-theme-mode.el,
etc.) but I prefer to manage all my Emacs extensions in a single place. That
place is my
~/.emacs.d directory, because I will eventually want an extension
that isn’t provided by my system’s package manager.
Download the color-theme.6.6.0.tar.gz and extract into
git add color-theme.6.6.0;
git commit -m "color-theme 6.6.0 from http://www.nongnu.org/color-theme/";
Add the color-theme directory to your Emacs
And actually load it:
Now you can select a theme with
The Solarized color theme for Emacs is available on github. If you are keeping
~/.emacs.d under version control using git, you can use git submodules
to simplify the management of such third-party packages.
git submodule add https://github.com/sellout/emacs-color-theme-solarized.git;
In future you can use
git pull from
to get the latest changes.
~/.emacs.d/emacs-color-theme-solarized/ to your Emacs
'color-theme-solarized, as you did for the
Now you can activate the theme with
You can toggle between fixed- and variable-width fonts in a particular buffer
variable-pitch-mode. The face to customize is
To automatically enable
variable-pitch-mode, add it to the hooks for all the
major modes where you want it to take effect. For example, to
for editing plain text.
If you really want it everywhere, I suppose there’s no harm in setting the
default face to a proportional font. The great advantage of
variable-pitch-mode, though, is that it is so easy to switch between
proportional- and fixed-width fonts when you come across some ascii art or an
ascii table in a comment.
I found this—after some dead ends—with Info’s
index command, typing
“font”, tab-completing, and trying whatever looked promising. I could just
have explored the Options menu instead, but—silly me—I had disabled the
menus because people on the internet said “real Emacs power users disable the
menus.” That might make sense on a text terminal, where you can’t click the
menu anyway, but on OS X, where there’s only one menu bar at the top of the
screen, it’s just silly. See the next footnote.
If you have disabled the menu, perhaps because you’re using an init file
copied from someone else or something like the Emacs starter kit, you can re-enable it just
for this session with
cd ~/.emacs.d; git init .; git add init.el; git status; git diff --cached;
git commit -m "My emacs init file."