sublime text helper in .irbrc

I wanted to be able to open helper methods from irb using sublime text on Mac OS X.

In order to do this you first need to create a command line helper to for sublime text.

ln -s /Applications/Sublime\ Text\ /usr/local/bin/sublime

This creates a symlink that you can use from the command line to open sublime text 2. Now we can use it in our .irbrc method.  Here is what i added to our .irbrc file:

def sublime(method_name)
  file, line = method(method_name).source_location
  `sublime '#{file}:#{line}'`

Now from IRB you can do this sort of thing:

>> helper.sublime(:link_to)

And it opens sublime text at the line number of the link_to method.

This is pretty nice. But, of course, what i’d really like is a way of opening the source for any method. Not sure how to go about that.

Also, if i could only get this to work with emacs. I can get emacs to open, but i haven’t spent the time to figure out how to get it to open to a given line number. Here is what i have:

def emacs(method_name)
  file, line = method(method_name).source_location
  `emacs '#{file}'`

The only clue to opening on a given line i found here, on stack overflow:

opening a file in emacs with at a line number.

Posted in emacs, rails, sublime text. Bookmark the permalink. RSS feed for this post. Leave a trackback.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Swedish Greys - a WordPress theme from Nordic Themepark.