Gedit mods for Groovy

Sooner or later you know that I would weigh in on editors for Groovy and Grails. I’ve tried ’em all–heavyweight IDE’s like Intellij, Netbeans, and Eclipse (I’ve listed those in preferential order), specialized editors like python’s SPE, commercial offerings like Komodo Edit and Ultra Edit for Linux, and general-purpose, *nix-loving editors like Vim (with or without Cream), and gedit. The winner for me is gedit. With an asterisk.

Gedit comes with Ubuntu distros, is the default Gnome editor, and indeed is integrated well into that window manager. It’s lightweight, it’s fast, it’s simple. And with a few simple plugin additions and mods (hence the asterisk), it makes a killer code editor.
First, go get the gedit-grails-bundle and follow the instructions. Provides some nice autocompletion, syntax highlighting, etc.
Second, activate or get some plugins:
Gedit comes with several, and many more are available through other sources. Just go to gedit’s plugin page and peruse the list. Here are the ones I deem indispensible:

  • Autocomplete, which is part of the gedit-grails-bundle – pops an autocomplete window
  • Smart Indent – provides language-specific indentation rules based on regex patterns. Part of the gmate plugin bundle, I believe. This is one your going to tweak for Groovy-specific autoindentation, below.
  • Snippets, included with gedit. The gedit-grails-bundle adds some nice Groovy-specific code snippets to this.
  • Snap open – hit ctrl-alt-O, start typing a filename, and it gives you a filtered list of files, a la TextMate.
  • File browser pane – Adds a left-hand pane directory structure–complete with Nautilus functionality–to gedit.

Grab any others you might want, as well. Plugins go in ~/.gnome2/gedit/plugins.
Next, you need to tweak your smart indent plugin:

  1. Navigate to the plugins directory, open the smart_indent file, and open __init__.py (in gedit, of course).
  2. Find the group of three lines that are java-specific regular expressions (“java_indent_regex”, “java_unindent_regex”, and “java_unindent_keystrokes”).
  3. Duplicate these lines in a group right below these three lines. 
  4. Rename the “java_” parts to “groovy_”. 
  5. For groovy_indent_regex, enter the following value: (\s*def\b\s+.*|.*\{\s*)
  6. For groovy_unindent_regex, enter the following value: ^\s\s+\}$
  7. For groovy_unindent_keystrokes, enter the following value: }
  8. Save the file, and you’re done!
Advertisements

About buffalobillion

Web Developer, JavaScript Balrog, Java dude, Ruby/Rails enthusiast. Guitar Playa.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s