ruby-mode for emacs

02 Sep 2007

I'm not really a ruby guy, but recently I had to do some ruby hacking, which means I needed ruby-mode for emacs. Between the InterWeb, RubyGarden, and EmacsWiki, I couldn't find a clear, correct description of how to get ruby-mode. Here's my take.

Step 1: Why not upgrade emacs?

Did you know emacs finally released a new version?!

If you are using MacPorts, do this for a terminal (non-gui version). Do port variants emacs for other options.

sudo port install -v emacs

Step 2: Download the code

We are going to install our lisp code in ~/.emacs.d/site-lisp which I think is more-or-less standard, but you could use any directory.

export SITE_LISP=~/.emacs.d/site-lisp
mkdir -p $SITE_LISP
svn export http://svn.ruby-lang.org/repos/ruby/trunk/misc ${SITE_LISP}/ruby
emacs -batch -f batch-byte-compile ${SITE_LISP}/ruby

Don't forget that last step! That compiles the lisp code, and will make emacs run faster (handy if you re-indent a large file).

Step 3: Configure your .emacs

Add this to your .emacs. This is a complete rip from RubyGardens's Installing Emacs Extensions, with the exception of the first line.

;; ruby                                                                         
;; based on http://www.rubygarden.org/Ruby/page/show/InstallingEmacsExtensions  
;;                                                                              

(add-to-list 'load-path "~/.emacs.d/site-lisp/ruby")

 (autoload 'ruby-mode "ruby-mode"
     "Mode for editing ruby source files")
 (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
 (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
 (autoload 'run-ruby "inf-ruby"
     "Run an inferior Ruby process")
 (autoload 'inf-ruby-keys "inf-ruby"
     "Set local key defs for inf-ruby in ruby-mode")
 (add-hook 'ruby-mode-hook
     '(lambda ()
         (inf-ruby-keys)))
 ;; If you have Emacs 19.2x or older, use rubydb2x                              
 (autoload 'rubydb "rubydb3x" "Ruby debugger" t)
 ;; uncomment the next line if you want syntax highlighting                     
 (add-hook 'ruby-mode-hook 'turn-on-font-lock)

Step 4: Get back to work

EOF


Comment 2007-10-06 by None

Hey,

Just wanted to thank you for posting this. I've spent all morning trying to get ruby mode to work, and this finally did it for me. Thanks!

-Jacob


Comment 2008-01-12 by None

Thank you! I was surprised by how little Emacs/Ruby info was available, I believe your page is the only one that clearly tells what needs to happen to turn ruby mode on.


Comment 2008-01-23 by None

Thanks alot! After reading like a dozen other sites and getting nowhere, this finally worked.


Comment 2008-02-17 by None

Another satisfied customer. Thank you


Comment 2008-04-24 by None

My thanks also! This was way too easy! And now back to work with increased ruby productivity ...

Vern


Comment 2008-07-13 by None

I've spent so much time looking for a decent guide. Yours worked! Thanks!


Comment 2008-09-05 by None

worked for me as well on openSUSE 11, thanks a lot


Comment 2009-04-14 by None

Thank you! This was simple and straightforward - now I've got ruby mode working in emacs on windows :-)


Comment 2010-09-01 by None

Yay!


Comment 2011-07-06 by None

Thank you so much for this direct and simple set of steps. I appreciate it