Sunday, January 9, 2011

Changing the Color Scheme in Emacs: the color-theme extension

If you are new to Emacs, as I am, you are probably are a little bothered by how it looks out of the box. Those of us who are just learning to use Emacs in this day and age have most probably worked with other editors (such as Textmate) that provide more eye candy right out of the box. There is no reason to be disappointed. As I have mentioned in earlier posts, Emacs is infinitely extensible and there are great color themes available to make Emacs more beautiful and more pleasing to your eyes.

For modifying the color scheme of Emacs you can use the wonderful color-theme extension. I recently installed it to work with Emacs 23.2 on Mac OS X. I have explained the steps below. These may work for other versions of Emacs.

  1. Go to http://download.savannah.gnu.org/releases/color-theme/ and download color-theme-6.6.0.zip to your computer.

    For the purpose of discussion, suppose you save this zip file in your ~/Downloads folder.
  2. Unzip the downloaded zip file. This will result in a folder named
    color-theme-6.6.0 within your ~/Downloads folder (or wherever you saved the color-theme-6.6.0.zip file).

    You may prefer to keep the color-theme-6.6.0 extension folder where you saved the color-theme-6.6.0.zip file, or you may prefer to move it to some other place on your computer where you keep downloaded Emacs extensions. If you want to move it to another place on your computer, ensure that you move the entire color-theme-6.6.0 folder. (I read this tip on some forum and had planned to link from here. Unfortunately, I deleted it and cannot find it again.)
  3. Add the following lines to your Emacs init file (~/.emacs file).
    (add-to-list 'load-path "~/Downloads/color-theme-6.6.0")
        (require 'color-theme)
        (eval-after-load "color-theme"
        '(progn
        (color-theme-initialize)
        (color-theme-dark-blue2)))
    
    Note that ~/Downloads/color-theme-6.6.0 is the folder where you saved the color-theme-6.6.0 folder. Also, dark-blue2 in the last line of the above code snippet is the name of one of the many available color themes. You can replace this by the name of the theme you like (see below how to find theme names).
  4. Close Emacs and start it again and enjoy the beautiful colors.

If you want to see the other themes that came with the extension that you downloaded, you can use M-x color-theme-select. This will open a new buffer with a list of available color themes. You can change to a theme in this list by moving the cursor to that theme in the buffer and pressing Enter.

If you want to see what different themes look like before changing yours, you can also go here: http://color-theme-select.heroku.com/#color-theme-light

2 comments:

  1. Thanks! This is the most straightforward how-to I found for color themes. Worked immediately, after several tries with other cryptic instructions.

    ReplyDelete
  2. I jut don't know how to thanks you! You saved my day. I can't understand why not everyone else on the internet tried to be even a bit as straightforward as you did. Again, thank's a lot!

    ReplyDelete