.rhtml minor mode

[ Update – new version is here: https://journal.dedasys.com/articles/2008/09/25/rhtml-minor-mode-update ]

Emacs has been my favorite editor for a long time, due to its incredible flexibility to meet new challenges, and extreme programmability. Things like tramp are just too cool to do without.

In any case, I’ve been doing more Ruby on Rails lately, and as part of that, have run into a few irritations with existing emacs tools. For instance, editing .rhtml files is not quite as nice as it could be. One reason is that psgml-mode, which I use to edit HTML files wants to have access to the DTD declaration in use. Since Rails usually puts fragments in one directory (app/views/foobar/show.rhtml), and the “parent” template in another (app/views/layouts/foobar.rhtml), it means that the “child” template doesn’t have access to the DTD in use, and so autocompletion of tags is not as accurate as it should be. Luckily, psgml mode provides a way to tell it that the parent is elsewhere. Utilizing this, I wrote a bit of elisp that automatically goes looking for the parent .rhtml file when you load up a fragment. It’s just an initial cut, and could use some improvement, but it seems to work for me:

http://www.dedasys.com/freesoftware/files/rhtml-minor-mode.el

On the TODO list:

  • Actually examine the layout file, to look for the top level tag that contains @content_for_layout.

  • Make _partials.rhtml type files work, or at least ignore them. The problem being that it’s hard to find out what tag they are contained within.

Patches, comments and suggestions are welcome!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s