Fixing HAML in jEdit
(This one is purely for tech people, Ruby on Rails developers who use jEdit to be exact.)
Chances are, if you use jEdit and HAML, you’re using or you’ve tried out Jim Morris‘ jEdit HAML edit mode.
If you’ve done so, and you’re using an up-to-date version of jEdit (e.g. 4.3 pre14) you’ll have noticed that the way it deals with indentation is really buggy. Here’s a description of the problem I posted to the jEdit mailing list, without much luck:
This is the code I want:
%table.form
= form_row("First name")
In the code above, as soon as I type the “a” in name (actually the point varies a bit, could be anywhere inside the double quotes), the line unindents, giving me this:
%table.form
= form_row("First na
This means that I have to go and reindent the line, so that it’s back the way I want it to be.
This also happens in cases where I am using braces { }. Here is the code I may want:
%a{:href => "/some/link"}
= "#{@user.login}"
As soon as I type the opening brace { in that string, the line unindents:
%a{:href => "/some/link"}
= "#{
And again, I have to reindent it.
What’s even more annoying (incredibly annoying!) is that after I reindent it, as I continue to type, it will continually unindent. So I end up fighting with my editor.
You can fix this problem by hacking up a new Ruby mode for jEdit that removes all of the indentation rules. Then, change the HAML edit mode to delegate to your new hacked Ruby mode, instead of the proper one.
Step 1:
Open the jEdit catalog file, probably in the modes folder (precise location depends on your system). Find the entry for Ruby and create a new one called ruby_stripped_down that references a new file called ruby_stripped_down.xml:
<mode NAME="ruby_stripped_down" FILE="ruby_stripped_down.xml" />
You don’t need all the info about file extensions, since this mode will only get called from the HAML mode.
Step 2:
Open up the ruby.xml file from the same folder as the catalog. Save a copy of it as ruby_stripped_down.xml. Now delete all of the lines inside the <props> tags near the beginning.
Step 3:
Open up the haml.xml file from the same folder. Wherever you see:
DELEGATE="ruby::MAIN"
Change it to:
DELEGATE="ruby_stripped_down::MAIN"
This occurs in four places.
Save it. Restart jEdit. Your problem should be solved.
If you’re lazy, you can also download my edited haml, ruby_stripped_down, and catalog files. However, be warned that overwriting your versions is at your risk (especially the catalog file – the others aren’t nearly as risky).