12
APR2006
Ruby Idioms Bundle for TextMate
[Update: An improved version of Ruby Idioms has been merged into the Ruby bundle in TextMate. Everyone gets Ruby Idioms with TextMate now.]
If you are a TextMate user (a Mac OS X text editor), we have something in common and you might be interested in the rest of this post. If not, skip it.
I have made my Ruby Idioms bundle available for anyone who would like to download it and try it out. This bundle contains all the Ruby shortcuts I use to program everyday. I've spent a lot of energy over the last six months refining them down to the keystroke, so hopefully there is a lot of value hidden in there.
If you just want to get to the goods and start playing, click the above link and run. However, if you want some insight into my thinking with these shortcuts, read on…
Tab Triggers
I'm a Unix guy, so I'm very comfortable with two or three letter triggers and that's what you are going to find here. Sometimes I use a one or two caracter trigger (r, w, and rw just make sense for attr_reader
, attr_writer
, and attr_accessor
, for example), but three is the norm.
I mention this because it is not the TextMate style and may be a turn off to some.
Iterators
All the core and many standard iterators are included in this bundle. I do mine differently from the normal TextMate style though, so I better mention that too. I find myself skipping around the object when it is included in the block more often than not (and I know where the escape key is when I do need the object), so I just want an empty block that leaves the snippet when I enter it (in case I need new triggers). That's my style.
Tests
I've included a compete set of test snippets in this bundle. It duplicates some work in the Rails bundle, but my opinion is that those tests are misplaced there anyway.
Automatic Requires
Some of my macros are really just snippets that ensure you have the proper require statement for the code. This can cause TextMate to flash the syntax highlighting because I have to replace all the code up to the cursor. If you would like to use the snippet, without the magic requires, just add a -
to the end of the tab trigger.
I use magic requires only where they make sense. For example, def_delegator
doesn't need one, because it's extend Forwardable
's job to handle that.
Idioms
You will find some imaginary methods as snippet names, like map_with_index
and flatten_once
. I use them because they are easy to remember names for more complicated idioms. I feel this is more natural, but some may be surprised when the inserted code doesn't look like the snippet title. Don't lose too much sleep over it, I say.
That Personal Touch
I wasn't kidding when I said these shortcuts are tuned to the keystroke. I've refined them after a lot of actual usage for what works best for me. You'll notice that extra tab stop in unix_filter
I leave in just to activate paragraph mode when I need it and that deleting OTHER_ARGS
in the option parsing code also removes the extra space. There are larger scale preferences too, of course. assert
needs a failure message, because it could be anything, but assert_equal
does not because the failure message makes sense from the method itself.
If you think like I do or can at least get into the flow, this should become pretty comfortable to work with. If not, it may just become a hellish set of magic rules you can't understand or remember. If the lattar is true, you may have to resort to you own bundle of tricks, but perhaps this will at least give you some ideas.
Comments (7)
-
thomas Aylott April 13th, 2006 Reply Link
Sweet.
-
Great bundle, extremely helpful, thanks!
-
Thanks the efforts to put this bundle out there.
I checked out the TextMate svn and while browsing the code found several references to your home directory in the bundlePath key. (grep bundlePath Macros/*.plist) I don't know enough TextMate to know whether that's a problem. Just thought I'd point it out.
-
Dave B: Allan tells me this is normal TextMate behavior.
-
-
I am a TextMate newbie. Has this stuff been added to the regular TextMate distribution (I purchased TextMate 2 months ago)?
I downloaded the file and double clicked. TextMate has installed it, but I think I should remove it and I don't know how.I have been using the Ruby and Rspec boundle with out any problems - other than I don't know what I am doing yet.
I enjoy your blog and use your book. I can't find out whether is OK to just remove the Ruby Idioms.tmbundle file from the application support/TextMate/... directory.
Thank you,
Carlton Mills,
Urbana, Illinois (birthplace of HAL)-
OK. I should have read more carefully. This was the beginning of the Ruby bundle that I have.
My bad!!
I disavow previous message and will deny it's existence. -
Yes, I just leave this post around for historical reference. The bundle is now the official Ruby bundle included with TextMate.
You can find help for deleting the bundle on the official site.
-