Getting the Solarized Theme to Work in Emacs

I discovered the Solarized color palette about a month ago, and have been using it since. I’ve found it helpful for reducing eye strain.

Getting the palette colors to accurately display in terminal-based Emacs under Ubuntu 11.10 took a bit of work. There’s a lot of scattered info about this topic if you google around. I first tried to do it with as little modification to my system as possible (I’m a minimalist), but I found that I absolutely had to do these three things to get it working.

1) Set the color palette in gnome-terminal. No matter what I tried, I could not get Emacs colors to look right without this step, so it’s a crucial one. Don’t skip it.

Solarized comes with an Xdefaults file, but that didn’t work for me. This blog post had instructions for setting gnome-terminal colors using gconftool-2, and that worked very nicely.

I put the commands in a handy little shell script that allows you to choose either the light or dark version of the palette. You can get it here:

https://gist.github.com/1397104

2) Your TERM environment variable needs to be set to “xterm-256color.” The default “xterm” will cause the Solarized color theme to look completely crazy in emacs.

Add the following line to your ~/.bashrc line (if you already set TERM there or some elsewhere else, change it instead of adding this):

export TERM="xterm-256color"

3) Use this version of the Emacs color theme for Solarized:

https://github.com/sellout/emacs-color-theme-solarized

Note that unless you’re using Emacs 24 (pre-release source code tarballs are available here), you’ll also need the color-theme package if you don’t already have it installed.

Put the files in a directory. In your .emacs file, you’ll need to add the directory to your load-path; I also added a bit of conditional logic for how to load the color theme in Emacs 23 and 24, since I switch between them:

(add-to-list 'load-path "~/.emacs.d/emacs-color-theme-solarized")
(if
    (equal 0 (string-match "^24" emacs-version))
    ;; it's emacs24, so use built-in theme 
    (require 'solarized-dark-theme)
  ;; it's NOT emacs24, so use color-theme
  (progn
    (require 'color-theme)
    (color-theme-initialize)
    (require 'color-theme-solarized)
    (color-theme-solarized-dark)))

That should do it.

3 thoughts on “Getting the Solarized Theme to Work in Emacs

  1. Ben

    Thanks so much for putting this all in one place. I found it very, very useful! I was having some trouble getting the emacs theme to work.

    As an aside, in Fedora 17 your emacs macro works fine without steps 1 and 2, though your script for changing the gnome-terminal colors is very useful for its own sake.

    Thanks again for posting such good instructions. Lisp is just not my cup of tea.

  2. Muhammed M

    Thanks a lot for these instructions. I have googled around but could not succeed until I saw your post.

  3. Pingback: Linux: Solarize theme on terminator | tyro2tiger

Leave a Reply

Your email address will not be published. Required fields are marked *