M-x all-things-emacs

Package Faves: emacs-rails

June 10th, 2007 by Rob Christie · 10 Comments

The emacs-rails package turns emacs into a Ruby on Rails IDE. To put it simply, I love the package. It gets me excited to see this much active development for an emacs mode. The emacs wiki has a laundry list of the functionality that the mode provides. I don’t think a single blog post can do the functionality justice, so I just want to hightlight a few of the features below (and expand on other features in later posts).

Context Sensitive Switching Between Rails Buffers

The rails framework espouses convention over configuration, therefore you can typically make assumptions that a method named edit in your controller is going to display a view that can be found under app/views/<controller name>/edit.rhtml. Additionally, due to the frameworks conventions there are a number of other files that are generally associated with a specific controller or model. M-Shift-up will take you directly to the primary file that is associated with the code location at point. M-Shift-down provides a list of other potential file options from which you can choose. For example, the screenshot below shows the results of pressing M-Shift-down when point is in the show method of the CompanyController.

Context Sensitive Switching Between Rails Buffers Example

Snippet Functionality

This functionality is actually derived from the
snippet.el package that provides another take on templating in emacs that closely mimics the templating functionality that is provided in TextMate. Snippet Example In the case of emacs-rails mode, these templates are tied to abbreviations. So if I type tcl and then tab while in a migration file, then a new line will be added to the table creation and my point will be placed in the area of the title of the column. When I am done updating the column name I can tab and I will be able to enter the type of column. I tab once again an I am out of the snippet editing mode. I think the rails-mode snippet integration is nicely done.

Invocation of Rake with Task Name Completion

C-c C-c r will prompt you in the minibuffer for the rake task that you want to run. Output of the rake task is then shown in a separate *ROutput* buffer. C-c / will toggle the showing or hiding of the output buffer. Rake tasks specific to testing are actually invoked via a separate command, C-c C-c t.

Invocation of Rake and Task Name Completion

For users that like to use the mouse and menus, all of the commands listed above can be accessed from the menu. I would also recommend taking a look at the two screencasts (here and here) that show emacs-rails mode in use, although there have been a number of changes to the package since the screencasts were made.

Tags: faves · rails · reviews · ruby

10 responses so far ↓

  • 1 carlos // Jun 10, 2007 at 1:07 pm

    which emacs should be used on a clean osx install?

  • 2 Timothy Wee // Jun 10, 2007 at 4:10 pm

    http://aquamacs.org/

  • 3 Ryan McGeary // Jun 10, 2007 at 4:37 pm

    carlos, I think there are only two worth mentioning, Aquamacs and Carbon Emacs. Here are my reasons for liking Carbon Emacs.

  • 4 Michael Nutt // Jun 10, 2007 at 5:57 pm

    In my opinion, the best way to get emacs on OSX is to compile it yourself. Of course, since building it yourself on OSX requires the free xcode download, you can also get prebuilt binaries here:

    http://www.porkrind.org/emacs/

    I’ve been using emacs-rails with it, and it works great.

  • 5 Nikolaj Schumacher // Jun 15, 2007 at 11:12 pm

    I’m glad about any kind of Emacs development happening. However, sometimes I can’t stop wondering how much of those “IDEs” like JDEE or emacs-rails could easily be made language-independent. Instead each builds their own set of tools and you have to learn a new one for each language. That somehow defeats the purpose of an all-in-one editor.

  • 6 Doug // Jul 11, 2007 at 4:51 am

    For OS X, there is also Emacs.app:

    http://emacs-app.sourceforge.net/

  • 7 Chad // Jul 12, 2007 at 5:05 pm

    I find that emacs-rails is a very useful mode. The only reason I can’t use it is that it automatically removes empty lines in files that contain spaces. When this happens and I check in code, it diffs all those lines. Anyone know how to stop emacs-rails from doing this cleanup automatically?

  • 8 Rob Christie // Jul 12, 2007 at 9:26 pm

    It is probably because of the write-file-hooks that are added in the untabify-file package. I would just comment out the adding of the hook untabify-before-write in the untabify-file.el.

  • 9 Arjen // Jul 20, 2007 at 8:46 am

    Hi, also take a look at a post I wrote last year about the different snippets and setting up rhtml stuff completely (Ruby On Rails and Emacs)

    At the time it was a complete overview of all available snippets…

    Arjen

  • 10 Rob Christie // Jul 21, 2007 at 1:35 pm

    Thanks for the link… and also for the great color theme.