Customizing a Theme for Emacs
What do you do when you are pretty comfortable with your Emacs theme and colors, but there’s one thing you have to change? You find the theme and you customize it to your liking. Here’s what I did.
When I switched to Debian on a Windows host a few weeks ago, I also switched back to darker colors. I looked for a matching Emacs theme and for a while I settled on my go-to sanityinc-solorized, but it didn’t do. I’ve used it at the office for too long and it just didn’t feel right. I also didn’t like the newer solorized: the headings change size in org-mode and I find that it breaks the visual harmony of everything else in Emacs. I ended up settling on Gotham, with its blueish-green colors and true-black background. The headings are all the same size too, thankfully.
One thing that stood out like a sour thumb though was the org-verbatim color font (that’s the format you get between two = signs in org-mode). org-verbatim font was a mild a dark gray, barely visible against the black background. I use org-verbatim to highlight lines of codes and commands, so the barely visible color was the opposite of what I needed.
I didn’t want to look up for a new theme, because I am fairly happy with Gotham’s colors and simplicity otherwise. Changing a single color in a theme can’t be that hard, I thought. I was happy to find out I was right.
downloaded themes from MELPA are saved in
~/.emacs.d/elpa. I don’t know why elpa and not melpa, but that’s what it is. I found the gotham theme folder, and opened gotham-theme.el.
Right at the top, under the first function definitions, I found the colors of the theme defined under
(defvar in hex. It looks like this:
(defvar gotham-color-alist `((base0 "#0c1014" ,(if gotham-tty-256-colors "color-232" "black")) (base1 "#11151c" ,(if gotham-tty-256-colors "color-233" "brightblack")) (base2 "#091f2e" ,(if gotham-tty-256-colors "color-17" "brightgreen")) (base3 "#0a3749" ,(if gotham-tty-256-colors "color-18" "brightblue")) (base4 "#245361" ,(if gotham-tty-256-colors "color-24" "brightyellow")) (base5 "#599cab" ,(if gotham-tty-256-colors "color-81" "brightcyan")) (base6 "#99d1ce" ,(if gotham-tty-256-colors "color-122" "white")) (base7 "#d3ebe9" ,(if gotham-tty-256-colors "color-194" "brightwhite")) (red "#c23127" ,(if gotham-tty-256-colors "color-124" "red")) (orange "#d26937" ,(if gotham-tty-256-colors "color-166" "brightred")) (yellow "#edb443" ,(if gotham-tty-256-colors "color-214" "yellow")) (magenta "#888ca6" ,(if gotham-tty-256-colors "color-67" "brightmagenta")) (violet "#4e5166" ,(if gotham-tty-256-colors "color-60" "magenta")) (blue "#195466" ,(if gotham-tty-256-colors "color-24" "blue")) (cyan "#33859e" ,(if gotham-tty-256-colors "color-44" "cyan")) (green "#2aa889" ,(if gotham-tty-256-colors "color-78" "green"))) "List of colors the theme consists of.")
Pretty straight forward. Now, how to find the piece of text which color I want to change? At the time I didn’t even know it was called org-verbatim. To find out, I went back to org-mode, found the color I wanted to change in the text, placed the mark on it, and used
M-x customize face. This can customize the font-face right there, but more importantly, it told me what font group the marker’s on as its default value. That’s how I found out that text is called “org-verbatim.” Knowing that I went back to the theme file and looked up for it.
Searching for org inside the theme brought up the org-mode group inside the .el file, which included quite a few colors, but not what I was looking for. That actually made sense: the definition of org-verbatim was missing from the theme, which meant it inherited the color instead. I am not sure how the hierarchy for these groups works, but it seems like org-verbatim just picked up the generic comment text color that should have a dim, out-of-the-way color. OK then. So, if it’s not there, why not add it?
Looking at how these colors were constructed in the .el file, I saw definitions like these:
(org-sexp-date :foreground cyan) (org-table :foreground violet) (org-time-grid :foreground yellow) (org-todo :foreground red :weight bold) (org-upcoming-deadline :foreground orange)
the colors themselves, like orange or cyan, were defined earlier under the defar part I mentioned above. So, all I had to do is to add this line:
(org-verbatim :foreground yellow)
Instead of re-evaling, I prefer to save the configuration and launch another copy of Emacs, which gives me a fresh copy of the results right next to what I’m working on:
Take a look: to the left, the frame with the setting before the change; to the right, the setting after the change.