Tuesday 23 October 2007

Gedit for Ruby (and everything else) on Gutsy, or No you don't need that Mac Mini.

You can find many blog posts online about turning Gedit, Ubuntu's default text editor, into a Textmate clone.

Unfortunately most of these posts no longer apply, because Gedit is now even better than before, as Gutsy Gibbon is now shipping with a new and improved version based on the GTKSourceView2 widget, which allows for context sensitive syntax highlighting, and big speed improvements, amongst other things.

The first thing you'll want to do is use your favorite package management front-end and install the gedit-plugins package, which includes a few extra plugins. Then go here, and follow his instructions on installing the mime types and lang files. He also has a few snippets, and other tips which are quite up to date. If you are running rails 2.0 you'll also want to edit his mime types file and add a couple of glob entries to handle the new view naming scheme.

<mime-type type="text/rhtml">
<sub-class-of type="text/html">
<comment>RHTML Template</comment>
<glob pattern="*.rhtml"/>
<glob pattern="*.erb"/>
</mime-type>

<mime-type type="application/x-ruby">
<comment>Ruby XML Template</comment>
<glob pattern="*.rxml"/>
<glob pattern="*.builder"/>
</mime-type>

You can find many more snippets here, and in case you don't understand Spanish, here are the files. You will only want to use his snippets and discard the rest though. Place them in '.gnome2/gedit/snippets'. There are other snippets around the web if you just google a bit. You'll probably end up customizing them a lot, i did. Also be sure to download the textmate-like syntax highlighting style. Place all downloaded styles in '/usr/share/gtksourceview-2.0/styles'.


Now just open up 'Applications->Accessories->Text Editor' and then in Gedit, 'Edit->Preferences' and check all options under View.



Then under Editor set your tab prefs, I like a width of 2 and I also check insert spaces instead of tabs, and enable automatic indentation.



Under 'Fonts and Colors' you might want to enable Darkmate or Oblivion. You can also download the monaco font used on apple, but remember that much of what he says in the post no longer applies, so tread carefuly.

Then under plugins be sure to activate: Bracket Completion, Embedded Terminal, External Tools, File Browser Pane, and Snippets. There is a Gemini plugin out there which does kind of what Bracket Completion does but I prefer the latter. You might also want to check out Session Saver, Class Browser, and Snap Open plugins. Check out this list of Gedit plugins.

You should now be good to go! A big heads up to Joselo, and Robert from Nationcode and Insane Terminology respectively, and Luigi for the textmate theme!

12 comments:

Robert said...

Hi! I've included the additional globs in my XML file for mime-types. Thanks for the tip!
By the way, you have a small typo in the post, this line:

<glob pattern="*.erb">

should be:

<glob pattern="*.erb"/>

otherwise it won't work and may cause some headache especially for those of us who are new to XML :)

crepuscular-homunculus said...

robzon, cool, thanks for that, i fixed it in the post. cheers, _c

Anonymous said...

Hi,

i wrote some usefull plugins for gEdit for webdevelopment:
http://my.opera.com/area42/blog/gedit-browser-preview-plugin
http://my.opera.com/area42/blog/gedit-language-reference-plugin
http://my.opera.com/area42/blog/gedit-template-plugin

These plugins making development sweeter

Anonymous said...

Hey man,
Thanks alot for the tutorial. I upgraded to Gutsy yesterday and then realized all my Rails customization "broke"!

I got all my snippets back and my rhtml files associated correctly.

Thanks!

Tyler Montgomery said...

Again thanks for the tutorial...I've been trying to get a lighter version of Darkmate working and I'm just about there. I can't seem to get erb tags (< % = ) to highlight...this was supported in Feisty but doesn't seem to have been implemented in the update that accompanied Gutsy...any ideas?

Vince Wadhwani said...

This has been helpful, thanks! One quick question: is there any way to have the bracket completion 'smart' so that it doesn't create a second set of brackets when you're closing the first (like textmate). e.g. If I type a single ' I get '' which is great, but when I start typing hello and close the bracket I'll get 'hello''' instead of just 'hello'

Anonymous said...

Thanks for the tutorial...been looking for a nice editor in Ubuntu. Very helpful!

crepuscular-homunculus said...

you're welcome everybody, glad it was of some use.

Anonymous said...

I've followed these instructions but when I open files that end with erb they start out (for syntax highlighting and snippets purposes) as html and I have to manually change them to rhtml. Any idea what might be the cause or what to do to make them all start out as rhtml when I open them?

Unknown said...

This didn't work for me either first up. I managed to get it to work though!

The problem was if I right-clicked on my rhtml files in Nautilus they had a different mime type to the one supplied in the rhtml.lang file. The mime type was "application/x-extension-rhtml"

This is what I did to fix the problem:

==== PROBLEM SOLUTION ======

1.) sudo gedit /usr/share/gtksourceview-2.0/language-specs/rhtml.lang

2.) change the third line from the top, which currently looks like this:

language _name="rhtml" version="1.0" _section="Markup" mimetypes="text/x-eruby"

Changed the mimetypes=, as follows (nothing else is changed in the line):

language _name="rhtml" version="1.0" _section="Markup" mimetypes="application/x-extension-rhtml"

After this change I closed down gedit, and double clicked on my rhtml file... and like magic, it worked!!

Hope that helps.

Christoph Olszowka said...

I have a set of snippets for gedit on GitHub. Read more on that on my Blog or check out the demonstration on Vimeo

Anonymous said...

don't forget the class browser plugin ...
Screenshot of mine :
http://img32.imageshack.us/i/geditide.png/