views:

485

answers:

4

Has anyone seen a vim indent file for treetop, the Ruby parser/generator? I've found a vim syntax highlighting file, but haven't seen one for indentation.

A: 

I'm not sure if there's a straight ruby implementation, but the vim rails plugin handles indentation quite well.

You could always just edit this so that it supports ruby files that aren't within a rails project. Check it out.

A: 

I searched for this a while ago for Vim or Emacs and couldn't find anything so I started writing my own mode for Emacs. It never got to anything since I pretty much stopped using TT but if my memory doesn't fail you only have to parse something like:

grammar Name
  includes # something like "include Something"

  rule rule_name
    tokens_or_rules {
      inner_method {
      }
    }
    <MyModule>
  end
end

Which might not be too hard after reading this.

PS: Keep in mind that this grammar is really similar to the one used by RSpec which is natural Ruby so maybe you could get some help by reading that.

Federico Builes
+2  A: 

It seems like it's fairly easy - I just create a file

~/.vim/indent/treetop.vim

and make its sole contents

runtime! indent/ruby.vim

and it seems to then support all I need. I think it just wasn't loading Ruby's indentation file!

Peter
Treetop files aren't Ruby though. They bear a strong resemblance, but that's all. Are you sure that using Ruby's indent file won't cause any problems?
Bob Aman
it seems to work pretty well so far. parts like do / end seem to be picked up correctly.
Peter
A: 

I copied the one from this guy: http://code.google.com/p/dot-files/source/browse/trunk/.vim/syntax/treetop.vim?spec=svn149&amp;r=149

Works beautifully.

Austin Taylor