Wolfmans Howlings

A programmers Blog about Programming solutions and a few other issues

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 :)

Posted in HAML,JEdit,Rails  |  Tags rails,jedit,haml  |  9 comments

Comments

  1. Frederick said on Sat Jan 20 22:00:02 -0800 2007
    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.
  2. Xarc said on Wed Jul 11 06:51:21 -0700 2007
    haml.xml doesn't exist...
    'Page not found'
  3. Xarc said on Wed Jul 11 06:56:58 -0700 2007
    Sorry for repeat. i find the correct URL:
    http://haml.googlegroups.com/web/haml.xml
  4. wolfmanjm said on Wed Jul 11 11:46:54 -0700 2007
    Thanks I fixed the link
  5. Gabriel Medina said on Thu Oct 02 02:06:28 -0700 2008
    Thanks a lot for your work.

    It's great. Just what I needed.

  6. Gabriel Medina said on Thu Oct 02 04:39:29 -0700 2008
    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

  7. Jesse said on Mon Mar 01 13:32:54 -0800 2010
    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.
  8. Jesse said on Mon Mar 01 13:32:58 -0800 2010
    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.
  9. Jason Padvorac said on Sun Jul 10 09:58:28 -0700 2011
    Thank you for releasing this! It makes editing HAML a lot nicer. :)

(leave email »)