Getting Groovy with TextMate
"Hmmm. I need to iterate over each line in a file. How exactly do I do that in Groovy?"The developer finds the answer he needs without ever leaving the editor. (Less context switching equals greater productivity, so it's an all-around win.) In fact, it's really a great way to discover various Groovy and Grails features. Just by looking through the available code snippets, a developer can quickly check out all sorts of APIs and idioms he might not have otherwise known about. Of course, you're not required to use the menu to benefit from the code snippets; you can also tab through various code completion options. Sticking with the example above, you can type
--
Goes to TextMate menu...
--
Bundles --> Groovy --> Iteration --> Files & Streams --> eachLine
File
, hit tab
, and TextMate inserts the same code snippet we'd get from the menu. If you're ready to give it a shot, just follow the pleasantly-simple installation process, and you'll be good to go.
- Download and untar the tarball.
- Copy the bundle files (Groovy.tmbundle and Grails.tmbundle) to ~/Library/Application Support/TextMate/Bundles
- Fire up TextMate and start groovin'!
$ ls -l ~/Library/Application\ Support/TextMate/Bundles/ total 0 drwxr-xr-x 5 jason jason 170 Nov 1 17:33 Grails.tmbundle drwxr-xr-x 6 jason jason 204 Nov 1 17:33 Groovy.tmbundle
--
For more examples of what you'll get from these bundles, be sure to check out the initial release notes.
And, there's still more to come. Graeme points out that these bundles are a work in progress. In addition to more code snippets, future releases will likely provide the ability to execute a Groovy unit test directly from within TextMate, execute a Groovy script inside TextMate, etc.
If you have a chance to try it out, shoot a quick note to the Groovy mailing list with your thoughts (or post a comment here, and I'll be happy to pass it along).
--
Update (2006-11-03)
Work in progress, indeed! Graeme has just added the ability to run Groovy scripts and Groovy classes from within TextMate.
To take advantage of these new features, first make sure you have Groovy installed and that your GROOVY_HOME variable is set. Then, just grab the current version of the bundle, install it, and you're ready to rock.
Once you've installed the latest bundle, open any Groovy file in TextMate, and hit Command + R to run the file in your editor.
Presenting...the gratuitous Hello World example...
Or, if you just want to execute the currently selected text, hit Command + Option + R to run just the selection.
Stay tuned for more updates as they come in.
--
Update (2007-01-13)
I modified the bundle links above to point to the locally hosted copy of the bundles, until such time that these bundles make their way to the official TextMate repository. Thanks, Martin, for this suggestion.
--
Update (2007-01-28)
The bundles still have yet to make their way to the official TextMate repository, but the Groovy site is now hosting a page on TextMate integration.
--
Update (2007-02-19)
At long last, the bundles have found a new home at the official TextMate repository. Not only have they found a new home, but you'll also find some nice new features in the latest revision of the bundles. So, if you previously fetched the bundles from anywhere other than the official TextMate repository, you'll likely want to upgrade to the latest version.