Custom colors for emacs
All nerds know about the epic geek battle between vim and emacs, the two most popular text editors for Unix and Unix-like systems (i.e. Linux, because calling “Linux” without the prefix “GNU” pisses Richard Stallman off so much, I will never call Linux GNU/Linux. That guy has got to learn when enough is enough.) Anyway, I, for no particular reason, am an emacs fan. It’s probably just because I used it first and climbed the steep keyboard shortcut learning curve and never turned back. I have no animosity towards vim users, developers, and even fanatics. I even use it occasionally when I’m logged into a machine that doesn’t have emacs installed.
Emacs can do anything. From reading mail, playing solitaire, to browsing the web, it is one of the most versatile, customizable systems around and the code base is well over one and a half million lines of code (see source analysis). Most of it is written emacs Lisp, a Lisp dialect that I will never bother to learn beyond the simple configuration changes I make to my emacs instances (list based languages though are quite beautiful and I have R. Kent Dybvig’s The Scheme Programming Language sitting in front of me now; Scheme is a LISP dialect as well). And that is the perfect segue into the topic of this tutorial: customizing emacs to use different color schemes.
Luckily, this is very easy to do but how you do it largely depends on what system you are using. The homepage tells you to use your Linux package manager to install it. This is obviously the right way to do it but at least for my system, Ubuntu (and ultimately Debian based Linux) stores this package in “emacs-goodies-el” so to install it type in a terminal “sudo apt-get install emacs-goodies-el.” (no period at the end) The homepage suggests adding the following Lisp configuration snippet to your .emacs file (should live in $HOME/.emacs):
(add-to-list 'load-path "/path/to/color-theme.el/file") (require 'color-theme) (eval-after-load "color-theme" '(progn (color-theme-initialize) (color-theme-hober))) <span id="more-461"></span>
But I don’t really think that is necessary since the package is installed in a directory emacs expects libraries to be in. Let’s say I wanted to use the “Robin Hood” theme. I would instead have in my .emacs:
(load-library "color-theme") (color-theme-robin-hood)
And that will load the Robin Hood theme each time you start emacs.
I decided to write this blog post after I finally switched from using the Robin Hood theme to Blue Mood (the transition can be seen below).

Robin Hood theme to Blue Mood
The Blue Mood theme is pleasing on the eyes to me but there was one little color setting that bothered me:

Blue mood styles class and class name both in yellow!
Notice that “class HttpResponseNotAllowed” is all the same color. The keyword “class” is fine being yellow as all the Python keywords are that same color (e.g. def, return, and self which are visible in the above image). But the name of the class should definitely not be yellow and I had to change it or I was going back to Robin Hood. Below is the change I made:

Class name changed to a "salmon" color to emphasize differentiation from the class keyword
The change is obvious and I think a good one: no longer is the class name colored yellow like all the keywords, but instead look like a function definition in color difference. Notice the get_host function where “def,” the keyword is in yellow and the function name in a shade of green. I decided on an unused color for class names and it is a “salmon” color (#FF8888).
It turns out that all themes are defined in a single Lisp source file, color-theme.el. So, I found the Blue Mood configuration and found the guilty color setting:
(font-lock-type-face ((t (:bold t :foreground "gold1"))))
in my opinion looks much better in Salmon, or
(font-lock-type-face ((t (:bold t :foreground "#FF8888"))))
We don’t want to change color-theme.el itself as it is bound to be updated at some point and your changes will be lost. So my solution was to copy the Blue Mood configuration from the aforementioned file and stick it in my .emacs file. I named my altered theme “Blue Mood Ryan Edit” and here it is, in all its simplicity in my .emacs file:
(defun color-theme-blue-mood-ryan-edit () "Color theme by Nelson Loyola, created 2002-04-15. Modified by Ryan Kaskel, May 2009. Includes cperl, custom, font-lock, p4, speedbar, widget." (interactive) (color-theme-install '(color-theme-blue-mood ((background-color . "DodgerBlue4") (background-mode . dark) (background-toolbar-color . "#bfbfbfbfbfbf") (border-color . "Blue") (border-color . "#000000000000") (bottom-toolbar-shadow-color . "#6c6c68686868") (cursor-color . "DarkGoldenrod1") (foreground-color . "white smoke") (mouse-color . "black") (top-toolbar-shadow-color . "#e5e5e0e0e1e1")) ((vc-annotate-very-old-color . "#0046FF")) (default ((t (nil)))) (blue ((t (:foreground "blue")))) (bold ((t (:bold t)))) (bold-italic ((t (nil)))) (border-glyph ((t (nil)))) (cmode-bracket-face ((t (:bold t)))) (cperl-array-face ((t (:bold t :foreground "wheat")))) (cperl-hash-face ((t (:bold t :foreground "chartreuse")))) (custom-button-face ((t (nil)))) (custom-changed-face ((t (:background "blue" :foreground "white")))) (custom-documentation-face ((t (nil)))) (custom-face-tag-face ((t (:underline t)))) (custom-group-tag-face ((t (:underline t :foreground "blue")))) (custom-group-tag-face-1 ((t (:underline t :foreground "red")))) (custom-invalid-face ((t (:background "red" :foreground "yellow")))) (custom-modified-face ((t (:background "blue" :foreground "white")))) (custom-rogue-face ((t (:background "black" :foreground "pink")))) (custom-saved-face ((t (:underline t)))) (custom-set-face ((t (:background "white" :foreground "blue")))) (custom-state-face ((t (:bold t :foreground "cyan")))) (custom-variable-button-face ((t (:underline t :bold t)))) (custom-variable-tag-face ((t (:underline t :foreground "blue")))) (ff-paths-non-existant-file-face ((t (:bold t :foreground "NavyBlue")))) (font-lock-builtin-face ((t (:bold t :foreground "wheat")))) (font-lock-comment-face ((t (:bold t :foreground "gray72")))) (font-lock-constant-face ((t (:bold t :foreground "cyan3")))) (font-lock-doc-string-face ((t (:foreground "#00C000")))) (font-lock-function-name-face ((t (:bold t :foreground "chartreuse")))) (font-lock-keyword-face ((t (:bold t :foreground "gold1")))) (font-lock-other-emphasized-face ((t (:bold t :foreground "gold1")))) (font-lock-other-type-face ((t (:bold t :foreground "gold1")))) (font-lock-preprocessor-face ((t (:foreground "plum")))) (font-lock-reference-face ((t (:bold t :foreground "orangered")))) (font-lock-string-face ((t (:foreground "tomato")))) (font-lock-type-face ((t (:bold t :foreground "#FF8888")))) (font-lock-variable-name-face ((t (:foreground "light yellow")))) (font-lock-warning-face ((t (:foreground "tomato")))) (green ((t (:foreground "green")))) (gui-button-face ((t (:background "grey75" :foreground "black")))) (gui-element ((t (:size "nil" :background "#e7e3d6" :foreground" #000000")))) (highlight ((t (:background "red" :foreground "yellow")))) (isearch ((t (:bold t :background "pale turquoise" :foreground "blue")))) (italic ((t (nil)))) (lazy-highlight-face ((t (:bold t :foreground "dark magenta")))) (left-margin ((t (nil)))) (list-mode-item-selected ((t (:bold t :background "gray68" :foreground "yellow")))) (modeline ((t (:background "goldenrod" :foreground "darkblue")))) (modeline-buffer-id ((t (:background "goldenrod" :foreground "darkblue")))) (modeline-mousable ((t (:background "goldenrod" :foreground "darkblue")))) (modeline-mousable-minor-mode ((t (:background "goldenrod" :foreground "darkblue")))) (my-tab-face ((t (:background "SlateBlue1")))) (p4-depot-added-face ((t (:foreground "steelblue1")))) (p4-depot-deleted-face ((t (:foreground "red")))) (p4-depot-unmapped-face ((t (:foreground "grey90")))) (p4-diff-change-face ((t (:foreground "dark green")))) (p4-diff-del-face ((t (:bold t :foreground "salmon")))) (p4-diff-file-face ((t (:background "blue")))) (p4-diff-head-face ((t (:background "blue")))) (p4-diff-ins-face ((t (:foreground "steelblue1")))) (paren-blink-off ((t (:foreground "DodgerBlue4")))) (paren-match ((t (:background "red" :foreground "yellow")))) (paren-mismatch ((t (:background "DeepPink")))) (pointer ((t (:background "white")))) (primary-selection ((t (:bold t :background "medium sea green")))) (red ((t (:foreground "red")))) (region ((t (:background "red" :foreground "yellow")))) (right-margin ((t (nil)))) (secondary-selection ((t (:background "gray91" :foreground "sienna3")))) (show-paren-match-face ((t (:background "cyan3" :foreground "blue")))) (show-paren-mismatch-face ((t (:background "red" :foreground "blue")))) (show-trailing-whitespace ((t (:background "red" :foreground "blue")))) (speedbar-button-face ((t (:foreground "white")))) (speedbar-directory-face ((t (:foreground "gray")))) (speedbar-file-face ((t (:foreground "gold1")))) (speedbar-highlight-face ((t (:background "lightslateblue" :foreground "gold1")))) (speedbar-selected-face ((t (:underline t :foreground "red")))) (speedbar-tag-face ((t (:foreground "chartreuse")))) (text-cursor ((t (:background "DarkGoldenrod1" :foreground "DodgerBlue4")))) (toolbar ((t (:background "#e7e3d6" :foreground "#000000")))) (underline ((t (:underline t)))) (vertical-divider ((t (:background "#e7e3d6" :foreground "#000000")))) (widget-button-face ((t (:bold t)))) (widget-button-pressed-face ((t (:foreground "red")))) (widget-documentation-face ((t (:foreground "dark green")))) (widget-field-face ((t (:background "gray85")))) (widget-inactive-face ((t (:foreground "dim gray")))) (widget-single-line-field-face ((t (:background "gray85")))) (yellow ((t (:foreground "yellow")))) (zmacs-region ((t (:background "white" :foreground "midnightblue"))))))) (load-library "color-theme") (color-theme-blue-mood-ryan-edit)
And now the theme looks better in my humble opinion. Cheers!
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.




Comments
No comments yet.
Leave a comment