49.1.8 Creating Custom Themes
You can define a Custom theme using an interface similar to the customization buffer, by typing M-x customize-create-theme
. This switches to a buffer named *Custom Theme*
. It also offers to insert some common Emacs faces into the theme (a convenience, since Custom themes are often used to customize faces). If you answer no, the theme will initially contain no settings.
Near the top of the *Custom Theme*
buffer, there are editable fields where you can enter the themeβs name and description. The name can be anything except βuser
β. The description is the one that will be shown when you invoke M-x describe-theme
for the theme. Its first line should be a brief one-sentence summary; in the buffer made by M-x customize-themes
, this sentence is displayed next to the theme name.
To add a new setting to the theme, use the β[Insert Additional Face]
β or β[Insert Additional Variable]
β buttons. Each button reads a face or variable name using the minibuffer, with completion, and inserts a customization entry for the face or variable. You can edit the variable values or face attributes in the same way as in a normal customization buffer. To remove a face or variable from the theme, uncheck the checkbox next to its name.
After specifying the Custom themeβs faces and variables, type C-x C-s
(custom-theme-write
) or use the bufferβs β[Save Theme]
β button. This saves the theme file, named name-theme.el
where name
is the theme name, in the directory named by custom-theme-directory
.
From the *Custom Theme*
buffer, you can view and edit an existing Custom theme by activating the β[Visit Theme]
β button and specifying the theme name. You can also add the settings of another theme into the buffer, using the β[Merge Theme]
β button. You can import your non-theme settings into a Custom theme by using the β[Merge Theme]
β button and specifying the special theme named βuser
β.
A theme file is simply an Emacs Lisp source file, and loading the Custom theme works by loading the Lisp file. Therefore, you can edit a theme file directly instead of using the *Custom Theme*
buffer. See Custom Themes in The Emacs Lisp Reference Manual, for details.