Autocomplete <% %> in Gedit
Posted by Vince Wadhwani on Apr 25, 2008
If you followed my previous post on using Gedit to do Ruby Rails development in linux you may have discovered the same annoyance I have. Like Textmate, < will auto-complete the > but unlike Textmate pressing <% will still only complete >. That's led to countless errors where I've accidentally created lines of code like:
<%= link_to "Bar", bars_path >
That lack of a proper closing %> naturally throws an error every time. I guess I'm still not over how textmate would do that automatically for me. Anyway, here's how you correct it.
Full disclosure.. I am not a python programmer. It's really Gary Haran's great plugin that does all the heavy lifting.. I've just modified it for one tiny railsism. How? Easy. Pop open gemini.py (it could be in ~/.gnome2/gedit/plugins or /usr/lib/gedit-2/plugins) and starting at line 50, change the code so it looks like this:
class Gemini:
start_keyvals = [34, 39, 96, 40, 91, 123, 60, 37]
end_keyvals = [34, 39, 96, 41, 93, 125, 62, 37]
twin_start = ['"', "'", '`', '(', '[', '{', '<', '%']
twin_end = ['"', "'", '`', ')', ']', '}', '>', '%']
The spacing is super important here so if you get an error check your spacing. (launch gedit from the command line to make sure it doesn't disable the plugin.. if it does you've got a spacing error)
With that done, you should automatically get <% %> each time you enter <%. The downside? This method isn't smart enough to not match the % by itself like Textmate is. Maybe a real python programmer wants to take a stab at that and share...