Home Download Buy Blog Forum Support

different syntaxes for .rb and _spec.rb files

different syntaxes for .rb and _spec.rb files

Postby DJMurtz on Mon Apr 18, 2011 7:44 am

I'm considering switching from textmate to sublime text 2 for my Ruby on Rails development. I very much like the customization options of the editor and the partial textmate plugin support. However, one thing I can't figure out is how to make ST2 open my rspec (testing) files with the rspec syntax highlighting and all other ruby files with the default Ruby syntax.

What I did was:

- Open a Ruby file (.rb) and select "Open all with current extension as Ruby on Rails"
- Open a Rspec file, which are all names *name*_spec.rb, this made the file open up with Ruby on Rails highlighting
- Selected "Open all with current extension as Rspec"
- Now all files (including simple Ruby files) are opened as Rspec (as expected, but not the way I want it)
- Next I opened both the "rspec.sublime-settings" and "Ruby on Rails.sublime-settings" files
- I readded "rb" to the Ruby on Rails file, as it was automatically removed in step 3
- I changed "rb" to "spec.rb" in the Rspec.sublime-settings file
- I deleted the Ruby.sublime-settings file (it was basically empty now)

But now all files are again opened in the "Ruby on Rails" syntax. So there could be two problems at work here;

1) the sublime-settings "extensions" hash only allows for the part after the "." (dot) to be set, in which case all Rails files can only have a single syntax set as the standard, which would probably make ST2 not the best RoR editor, but I doubt thats the case here.

2) Somehow, the RoR settings take precedence over the Rspec settings, but I don't know why.

Anyone here who figured this out and could help me out here? Thanks.
Posts: 28
Joined: Mon Apr 18, 2011 7:27 am

Re: different syntaxes for .rb and _spec.rb files

Postby DJMurtz on Mon Apr 18, 2011 8:50 am

For those of you interested in this (if it isn't already implemented in the editor and I somehow missed this feature),

here is a modified python plugin (original snippet here) which works with ST2 and switches syntax language based on your own rules. It's crude (no exception handling or whatever) and it's my first python script ever, but it works for me, so perhaps it's useful for you too. Just place it in your Packages/User directory and modify it if you want different tmLanguage files to be loaded for different filenames/types.

Gist: https://gist.github.com/925008

(677 Bytes) Downloaded 195 times
Posts: 28
Joined: Mon Apr 18, 2011 7:27 am

Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 32 guests