fredag 7. oktober 2011

Textmate made friendly for running Groovy snippets

I seem to remember Scott Davis doing a groovy presentation at JavaZone in 2008 or was it 2009, using Textmate. Didn't think much of it at the time. I had enough editor confusion going on,  switching from eclipse to idea.

Earlier this week a colleague and I was working on a Groovy introduction presentation and we had decided on using textmate. So we downloaded the capable Groovy textmate bundle from Github. I had been using the Groovy console and found the performance for running small groovy snippets to be rather unbearable with the textmate plugin though. You got the startup cost of firing up the jdk+groovy and it opened a new window. This was not what I remembered, and it certainly wouldn't work for a code driven presentation. A quick google found a youtube video with Dierk König. Aha of course Groovyserv to the rescue.


So the short version:
  1. Got Homebrew ? Well then just  brew install groovyserv
    1. No ? Install it (if you don´t have xcode either... I suggest you download groovyserv manually unless you have the time to spare. People complain about maven downloading the internet, xcode feels pretty close)
  2. In textmate select bundles->bundle editor->edit commands
  3. Add a command for running the current file. The following settings might work for you:
    1. Save current file (usually what I want)
    2. Commands : /usr/local/Cellar/groovyserv/0.9/libexec/bin/groovyclient -encoding "UTF-8" "$TM_FILEPATH"
    3. Input : Entire document
    4. Output: Show as tooltip (worked out real nice in the presentation)
    5. Activation : cmd+h (or something that suits you... that particular combination has a somewhat different behaviour in the GroovyConsole btw)
  4. Similarily if you just want to run a selection just change command to something like:
    1. /usr/local/Cellar/groovyserv/0.9/libexec/bin/groovyclient -c "UTF-8" -e  "$TM_SELECTED_TEXT"
  5. Unlike the console it doesn't output the last executed statement, so if you are doing oneliners you better remember println ! (If anyone has any tips for that one in Textmate, feel free to comment on the post)

You are all set to run nice little groovy snippets with near instant responses (well the first time you try it, groovyserv will incur a heavy startup cost. But after that you are good to go in kickass speed).

Ingen kommentarer:

Legg inn en kommentar