Toggling light/dark Solarized color theme in Emacs 23

I never write about Emacs because I’m such a n00b and most of my ELisp “programming” has consisted of pasting random code from the Internet into my ~/.emacs file and hoping it works. But finally today I wrote a lick of it and it worked!

I’ve been using Ethan Schoonover’s obsessively comfortable “Solarized” color scheme for a while now, but I’ve become annoyed how many keys I have to mash to switch from light to dark. So I set a global variable to track the current state and mapped Ctrl-c, d (which I at least wasn’t using) to a function to toggle between the two states.

(when window-system
  ;; ColorTheme - see
  ;; and see gallery at
  ;; try also M-x color-theme-select
  (message "loading color-theme")
  (add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
  (require 'color-theme)
  ;; Ethan Schoonover's Solarized theme from
  (load-file "~/.emacs.d/emacs-colors-solarized/color-theme-solarized.el")
  ;; Set initial theme to "dark"
  (setq dark-or-light 'dark)
  (color-theme-solarized dark-or-light)
  ;; Shortcut to toggle between light and dark
  (global-set-key (kbd "C-c d")
                    (lambda ()
		      (if (eq dark-or-light 'light)
			  (setq dark-or-light 'dark)
			  (setq dark-or-light 'light)
                      (color-theme-solarized dark-or-light)))

And ooh, I just found this awesome crash course on Elisp by Steve Yegge which I will certainly consult next time I have a reason to write my own (i.e., I can’t paste it from some random Internet).

And then after it was all over I finally found some instructions for doing it which would’ve been easy enough to paste. Ah well, I’ve learned something.