CNK's Blog

Rspec output not colorized in emacs

Now that my machine is at least partially set up, I thought I would actually pull down some code from Github and do some programming. I have git, RVM, and sqlite3, so setting up a working environment took ~5 minutes. But there has been another security update since I last touched this code, so I thought I should start by updating everything to Rails 3.2.6 and checking to see that nothing breaks.

Well two things are broken. I now have a number of tests that are not passing. But I’ll have to get back to that later. More importantly, the colorization in my shell within emacs is broken. No pretty green (or red) in my rspec output. Not acceptable.

So first, what is the name for the system that takes the weird ^[[32mAnd "^[[32m^[[1mGe characters and turns them into pretty colors? Apparently that is called Ansi colors: http://en.wikipedia.org/wiki/ANSI_escape_code. On my Linux machines, the emacsen have ansi color interpretation turned on by default. In fact, the docs I can find for the ansi-color eLisp code indicate that colorization has been the default since ~1999. But whatever. Folks on the emacs IRC channel had a number of suggestions about how to get that working (including suggesting not using ansi-color.el but using xterm-color.el instead). The incantation that finally worked on the emacs that shipped with Lion (emacs 22.1.1 ©2007) is:

     (ansi-color-for-comint-mode-on)

While I was customizing my settings, I copied some configurations from some of my other .emacs files into here. I wasn’t sure they were compatible with the installed emacs 22 (I run emacs 23.3.1 on my server) so I tried out the automatic mode setting for Rakefiles. But, to my horror, there isn’t a ruby-mode installed here. Hmmm guess it is time to explore installing a more recent emacs.

Emacs from Homebrew

Braumeister shows an emacs 24.1 formula. Let’s see what that is like.

     ==> Downloading http://ftp.gnu.org/pub/gnu/emacs/emacs-24.1.tar.bz2
     ==> ./configure --prefix=/usr/local/Cellar/emacs/24.1 --without-dbus --enable-locallisppath=/usr/local/share/emacs/site-
     ==> make
     ==> make install
     ==> Summary
     /usr/local/Cellar/emacs/24.1: 3880 files, 102M, built in 2.1 minutes

Ahhhh much better! I have ansi color by default. And more importantly, I have ruby-mode AND my hook for automatically invoking ruby-mode for .rb, .rake, and .spec files works!

And one small tweak for this blog. The .markdown files for this blog have been opening in Fundamental mode without auto-fill on. I think text mode with auto-fill on would be more sensible:

     (add-to-list 'auto-mode-alist '("\\.markdown$" . text-mode))
     (add-hook 'text-mode-hook 'turn-on-auto-fill)

Ok now am I set up to code?