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.
4 Answers
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!

- 127,331
- 53
- 180
- 211
-
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 Oct 25 '09 at 18:22
-
it seems to work pretty well so far. parts like do / end seem to be picked up correctly. – Peter Oct 27 '09 at 00:43
I copied the one from this guy: http://code.google.com/p/dot-files/source/browse/trunk/.vim/syntax/treetop.vim?spec=svn149&r=149
Works beautifully.

- 5,437
- 1
- 23
- 29
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.

- 4,939
- 4
- 34
- 48
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.