A HAML edit mode for JEdit
Posted by Jim Morris on Fri Dec 01 18:09:47 -0800 2006
I've just started a new RoR project and thought I'd try out HAML for the views instead of rhtml.
Seeing as I just switched to JEdit, I looked for a HAML language mode, and to my surprise no one had done one yet.
So here is my first attempt at a language mode for JEdit and version 1.0 of the HAML language mode. It needs more work, and I hope someone with a better understanding of JEdit language modes will help out.
This will set the indent to 2 spaces and auto-indent after a %tag that has nothing else on the line...
%p
stuff
It will not auto indent if there is more stuff on the line like in the
following example the line after %p
gets indented but the line
after %label
does not.
%p
%label{ :for => "login" }Login
%br/
= f.text_field :login
I have setup a basic syntax coloring scheme that should color %tags
and .classes
and #ids
differently. It will color anything
following an =
or ~
and defer the syntax highlighting to the ruby
mode for anything following them, ditto for anything inside { }
.
Feedback and better ideas are welcome.
Download from here
To install copy the file to ~/.jedit/modes, and edit the catalog file in that directory and add this line:
<MODE NAME="haml" FILE="haml.xml" FILE_NAME_GLOB="*.haml" />
Then restart jedit, and your haml files will be syntax highlighted.
I like HAML but there simply is not enough example code out there yet, so here are two simple conversions from well know rhtml files into HAML...
First the standard login form from acts_as_authenticated
- form_tag sessions_path do
%p
%label{ :for => "login"} Login
%br/
= text_field_tag 'login'
%p
%label{ :for => "password" }Password
%br/
= password_field_tag 'password'
%p
%label{ :for => "remember_me" }Remember me:
= check_box_tag 'remember_me'
%p
= submit_tag 'Log in'
Next the new user form from the same place...
= error_messages_for :user
- form_for :user, :url => users_path do |f|
%p
%label{ :for => "login" }Login
%br/
= f.text_field :login
%p
%label{ :for => "email" }Email
%br/
= f.text_field :email
%p
%label{ :for => "password" }Password
%br/
= f.password_field :password
%p
%label{ :for => "password_confirmation" } Confirm Password
%br/
= f.password_field :password_confirmation
%p
= submit_tag 'Sign up'
If this is dumb HAML coding please let me know how to improve it :)
Hey, I've been looking for this. Thanks a lot for sparing me the pain of constructing an edit mode myself. Although I might have some energy to put into helping you improve it in the future. Seeing as I'm stuck with jEdit for some time before I earn enough money to go buy a Mac and use TextMate, I'm happy that at least now it's a bit more bearable.
haml.xml doesn't exist...
'Page not found'
Sorry for repeat. i find the correct URL:
http://haml.googlegroups.com/web/haml.xml
Thanks I fixed the link
Thanks a lot for your work.
It's great. Just what I needed.
Hi there, I was inspired by your HAML jedit mode, and wrote a SASS mode myself,
it's here:
[SASS jEdit Mode for Syntax Highlighting](http://rha7dotcom.blogspot.com/2008_10_02_archive.html)
Hope this is useful for you.
Gabriel Medina
If you're wondering why the buffers you had open still don't work, maybe even after you've closed them and reopened them, it's because jedit saves buffer options per file even after you close.
To change it, go to Utilities->Buffer Options->Edit mode
New files will open and use the modes just fine.
If you're wondering why the buffers you had open still don't work, maybe even after you've closed them and reopened them, it's because jedit saves buffer options per file even after you close.
To change it, go to Utilities->Buffer Options->Edit mode
New files will open and use the modes just fine.
Thank you for releasing this! It makes editing HAML a lot nicer. :)