home::blog::wump
there are only 10 kinds of people in this world..

How to customize the Gemini gedit plugin

Posted by Keith Fri, 25 Apr 2008 14:48:00 GMT

gedit is Textmate for Linux

I’m a recent convert to gedit for my rails development after reading a digg article about how to make gedit act like Textmate. Well I’ve never used textmate, but after just a short spell of using some textmate like features, I’m sold too.

Gemini

One of the two plugins that I’ve grown to love is Gemini by Gary Haran for the auto-insertion of closing tags.

I like it, but it also drove me nuts in it’s default form, in that it auto completes the single apostrophy - fine in code, but if you are jumping back and forth between code and text creation then this is really annoying. Words like “doesn’t”, “hasn’t”, “don’t” etc. all kick off the closing quote - not ideal.

Removing and adding rules to Gemini

The beauty of Open Source is you can change it. If I knew Python, what I should really be doing is contributing with a “configuration” screen for Gemini, but I don’t - so I’ll just hack it.

To remove the single quote rule, open the file:

/.gnome2/gedit/plugins/gemini.py

and search for

“class Gemini:”

  start_keyvals = [34,  39,   96,   40,   91,   123,  60]
  end_keyvals   = [34,  39,   96,   41,   93,   125,  62]
  twin_start    = ['"', "'",  '`',  '(',  '[',  '{',  '<']
  twin_end      = ['"', "'",  '`',  ')',  ']',  '}',  '>']

and change to:

  start_keyvals = [34,   96,   40,   91,   123,  60]
  end_keyvals   = [34,   96,   41,   93,   125,  62]
  twin_start    = ['"',  '`',  '(',  '[',  '{',  '<']
  twin_end      = ['"',  '`',  ')',  ']',  '}',  '>']

Restart gedit and you are good to go!

Adding rules, eg. % for Rails

Adding is pretty much the same process. In Rails views, you often use:

<% content %>

so it would be great if Gemini had a rule for % and that’s really simple. Looking again at this block of 4 lines of code, what we have is 2 lines that state ASCII values, and 2 lines that show the character.

By modifying and adding % and it’s ascii value 37, we end up with:

  start_keyvals = [34,   96,   40,   91,   123,  60, 37]
  end_keyvals   = [34,   96,   41,   93,   125,  62, 37]
  twin_start    = ['"',  '`',  '(',  '[',  '{',  '<', '%']
  twin_end      = ['"',  '`',  ')',  ']',  '}',  '>', '%']

Restart gedit, and typing “<%” in a view now kicks off the <> and %% rules - awesome.


Comments

Leave a response

Comments