A Ruby IDE: Why TextMate Is Close Enough

Posted by kev Wed, 06 Sep 2006 10:04:00 GMT

Recently Tim Bray posted a list of things he has found that Ruby needs. One of these things is an IDE and he provides a list of useful things one would do for us. I’m not sure if Tim has tried TextMate, but if you’re aware of the right features it turns out to almost be exactly what he’s looking for. The remaining features might be implemented by the right group out in the Lazy Web (do these things and we’ll all be grateful). Anyway, here’s interesting things you may have missed about TextMate in the context of Tim’s wish for an IDE.

Automatic Syntax Verification

Tim says:

There should be a background parser running all the time so that you always know if you have syntax errors and can jump to them with one click; it is so totally a waste of time for me to save, then try to run, a file that the computer is in a position to know won’t work.

Part of this is built right into TextMate. Control-Shift-V will give you a message telling you either that the syntax is OK or there’s an error and it’s on line X. Not automatic yet, but I think this should be doable for some determined hacker.

Code Completion

Tim says:

I shouldn’t have to type the names of well-known methods, like File.new or (anything).each, or type in closing parentheses or the keyword end, or fill in more than a couple of characters of begin/rescue/ensure structures; it is never correct for a human to hit keys when a computer, in principle, could provide the input.

I agree wholeheartedly. Fortunately, TextMate provides most of these things in the Ruby bundle (you may need to grab the svn bundles (svn info at the bottom)). Things like dealing with closing parens are built into the Ruby language scope. They’re done automatically. For defining methods I write def and hit tab and boom, I’ve got a method definition. Similar tab completion exists for each (ea + tab), do, and begin. I don’t type the end keyword anymore. Even better, TextMate’s bundle editor is fantastic. Adding snippets, commands, and support for new languages is simple enough that I didn’t need to look at the documentation to create my own bundle for Pragmatic Markup.

Refactoring Support

Tim says:

The computer should help with refactoring; and all you really need is renaming. I regularly want to change the names of classes and variables and methods (if only to add or subtract a @), and it is so so stupid that I have to go mousing all over my files to find all the places that the name needs changing; that’s what computers are for.

This would be really nice. I’ve got to admit, Eclipse has us beaten there (though static typing helps this a lot). If you really just need renaming then Find (includes replace, Command-F) will probably work. If you need it across a project Find in Project should work (Command-Shift-F). Regex handling is of course right there when you need it.

I’m not completely satisfied with the offerings here. A refactoring browser is definitely on my wish list for things that would enhance Ruby.

Quick Navigation

Tim says:

I should never have to scroll much; IDEs go to a lot of trouble to make it trivial to jump from wherever to the source for the method being called, or its docs, or the next compile error or breakpoint, or variable declaration, or whatever. Scrolling back and forth in a source-code file is just stupid.

This one you may have seen in a screencast and never thought twice about. If you’ve got more than one file open (a project or directory works) Command-T brings up a “Go to File” dialog. You can then type in bits and pieces of the file name and there you are. You really need to use this to believe it. The pattern matching is great. When I remember to use it, Command-T replaces the mouse for moving between files.

Slightly more obscure is the “Go to Symbol” dialog (Command-Shift-T). This is great if you’re jumping around inside files. This is like “Go to File” but for your classes and methods. As soon as I really pound it into my brain that it makes sense to use it over my scroll wheel (the damn this is breaking down.. this is a sign) I have a feeling it will be my new best friend.

Oh oh, one last thing on these two bits: they use most-recently used lists so it’s really easy to switch back and forth between a few files. It also seems to remember how patterns were used and puts commonly accessed files at the top.

As for jumping to lines in files on errors, I know I remember TDDMate doing this. I’m not sure how, but I’ve seen it done so we should be able to incorporate it in other TextMate hacks. If anyone is interested, please do investigate.

Unit Testing Integration

Unit testing should be part of the infrastructure. To create a test, or run a test, or look at test results, you shouldn’t have to hit more than one keystroke.

TDDMate tried to do this for Rails. Though it seems to have moved on, short cuts for tests are still in the Ruby bundle. Command-Shift-R (Run focused unit test) makes me happy. I can just run that one test method I’m working with in a tap of the keys. Creating a test in Ruby is trivial (def + tab test_something + tab + write assertions!). TDDMate had a key shortcut to run all unit tests, but in the absence of that Control-Shift-R (run Rake task) should do. It pops up a dialog with all the available Rake tasks. If you’re running tests, it shows output in the built in TextMate runner. I’m sure it could be modified to let you click on a line in a stack trace and take you to that line in the file. I’ve seen it done. Someone make this happen.

So, Tim, I think TextMate will do what you need. If you’ve been an emacs guy (that’s what I hear around the caboose water cooler) then I’m told the transition is smooth. Well, really, the transition is smooth no matter what. Give it a shot.

Update: I forgot to mention that TextMate also just got ruby-debug integration. If you need to use a debugger in Ruby (it doesn’t happen often, but it happens) ruby-debug seems to be the way to go. Cool eh?

Posted in , ,  | 14 comments

Comments

  1. Avatar James H said about 3 hours later:

    AFAIK Tim has not tried TextMate. A while back he made a post about Emacs and I had suggested TextMate to him as a possible alternative. He didn’t see why he should want to switch, let alone pay for something that more or less has the same functionality.

    A point of interest though: in TextMate, when doing Ruby, if you type 'deft' then press tab, you generate:
    
    def test_case_name
    
    end
    
    

    Also, for those who want to learn a whole lot about TextMate’s bundling system, PeepCode has a screencast for sale covering just about everything you could ever want to know.

  2. Avatar Jeff said about 3 hours later:

    I don’t know if Tim uses a Mac (he probably does), but don’t forget some of use an operating system that don’t run TextMate :-) I personally use Notepad or Scite for most Ruby code, and switch to the RideMe IDE for editing Rails projects on Windows.

    I’m sure TextMate is awesome – I just don’t have $2000 for a new text editor right now. :-)

  3. Avatar masukomi said about 3 hours later:

    The only problem with TextMate being that it’s only on OS X which leaves the vast majority of the world’s hackers out in the cold. So, while it’s good I don’t really count it or any other app that’s limited to such a small segment of developers as a realistic answer to the need.

    It’s like saying “we really need water” and suggesting that that’s not an issue because 10% of the population (or whatever Apple’s market share currently is) has plenty.

  4. Avatar Todd said about 4 hours later:

    I’m a big fan of Komodo IDE (http://www.activestate.com/Products/Komodo/?mp=1). Sure it costs some money, but there’s a $30 version for non-commercial use. Works great with Rails, too.

  5. Avatar Kevin Clark said about 5 hours later:

    Hi Guys, Yes, I know TextMate is Mac only ;)

    I’m not suggesting everything is roses because TextMate can do these things but a significant portion of the Rails community seems to have embraced OSX. For that large chunk TextMate will suffice. For the rest of you… well, you could try to coerce Alan to write a version for Linux but I’d be surprised if he’d touch Windows.

    If you really feel like you need these things a Mac Mini might be in order. I’ve got a Duo mini with 2 gigs of RAM as my main development box these days and I’ve never been happier. It cost just about $1k in all so I had enough left over to grab myself a decent monitor.

  6. Avatar MikeInAZ said about 6 hours later:

    @Jeff

    Actually you could spend around $1200 (@amazon) for a nicely equipped Macbook, less if you don’t need a DVD burner.

    So it’s only about $1250 for an awesome text editor :)

    Yeah, that’s still a lot of clams. But you can’t make clam chowder without breaking some clams or something…

  7. Avatar Todd Huss said about 6 hours later:

    Don’t forget RadRails http://www.radrails.org/ , I switched from Textmate a while back and haven’t looked back. Coming from the Java / Eclipse world I found it a fairly easy transition. It’s still a work in progress but I use it for all my Ruby coding now.

  8. Avatar Sarah said about 8 hours later:

    In addition to TextMate, Vim shouldn’t be overlooked. Useful links:

    How to use Vim with Rails

    Abbreviations

  9. Avatar Joe Ruby said about 9 hours later:

    LOL, yes vim should be overlooked. As a very long-time user of vim, I can never understand why anybody would recommend it as an IDE.

    As for TextMate, yep, it’s good enough.

  10. Avatar Dave Astels said about 11 hours later:

    I used TextMate when I started playing with Rails last fall. I asked and that’s what everyone recomended. After seeing Kyle’s CoR talk on RadRails I gave it a try. I’ve since switched back to TextMate and “haven’t looked back”.

    masukomi: Apple is, iirc, up to around 20% now. And OS X seems to be the overwhelming standard platform for Rails work. As for Mac and the world’s hackers… I guess you don’t read Paul Graham (http://www.paulgraham.com/mac.html).

  11. Avatar Kyle Shank said about 23 hours later:

    Who cares?

    As RadRails approaches its first anniversary its clear to me that an editing experience really comes down to the individual. There is no one size fits all. RadRails won’t be the solution for everyone but hey at least its free and everyone can try it out.

    Some people like to have the cool overpriced jeans, thats fine. I develop on a Mac too. The argument that you should just go get a Mac just to use Textmate is bullshit and ironic in an open source world.

    We have ruby refactoring support coming in RadRails as well as ruby-debug integration. Look forward to seeing anyone whos gonna be in London next week.

  12. Avatar Gabe said 1 day later:

    I don’t have a ton of experience with IDEs (a little Eclipse, Xcode, some Borland back in the day), but my sense is that IDEs are custom tailored to integrate with specific platforms very well. An IDE can be so good that people just swear by it and feel crippled if they go to another platform (MS IDE anybody?)

    TextMate focuses on being extensible, so I put it more in the Emacs camp. Although, frankly, I find it easier to customize than Emacs (what can I say, I’m a vi guy).

    So I think initially TextMate falls short of an IDE, but it makes up for it with it’s easy customizability. It sort of lets you create a DSL for your personal work patterns. It ties into the shell so if you’re a UNIX junky you have an unlimited toolkit at your disposal. It ties into AppleScript if you’re into that whole thing (which I know nothing about, but is pretty cool I think). Once you understand it, you can replicate 95% of what any IDE does. Of course, it was designed specifically in the presence of Rails and sponsored by DHH (without whom it might never have seen the light of day), so it’s pretty good for Rails out of the box.

    If you’re not using a Mac then obviously it’s no solution, but a lot of Rails developers do use Macs exclusively, so it can be a complete solution for some. I’m always excited to hear about RadRails development even though I don’t see myself using it anytime soon.

    Some choice TM tidbits:

    Ctrl-H for Rails documentation Shift-Option-Command Down-arrow for navigating between related files

  13. Avatar Pascal said 1 day later:

    Textmate is really cool indeed. I use cmd-T all the time and wish cmd-shift-T would work across all files.

    I didn’t know about the ctrl-shitf-v trick and I thank you for that.

    As far as line number go, you can use the textmate_footnotes plugin to get clickable stack traces in the browser (ruby-debug can also open files to texmate via tm[ate] n #n is the frame number of your stackframe).

  14. Avatar Nathan said 5 days later:

    There is a wonderful unit testing tool for ruby called autotest (short description and screencast here). It’s as simple as typing “autotest -rails” at the console from your project’s top level directory. It finds all of the tests and runs them, and it monitors the test tree for new tests and changes to existing tests. Every time something changes, the changed/new test is run. So, there’s literally no typing or mousing necessary. As soon as you change a test, you know if it passes or fails. It’s still a young tool, but it works pretty well. It’s definitely something to keep an eye on.

Comments are disabled