How to correct syntax highlighting for setting Rails link or form field "class" in Sublime/Textmate 2

ruby, ruby-on-rails, sublimetext, sublimetext2, textmate

Solution

I think it's to do with the precedence in terms of syntax highlighting. Because the keywords for ruby matches "class" it is trying to highlight it as though you had `class MyClass`. Whereas the old format of hashes had the preceding `:` to stop it from being picked up as a keyword.

Disclaimer: I'm no expert on this stuff was just tinkering and the following worked for me.

If you edit your Ruby.tmLanguage file (in Packages/Ruby) you can move the section that defines keywords below the section that defines the new ruby 1.9 hash syntax. That way it should prioritize the new hash syntax.

Look for a `<dict>` entry that contains:

<dict>
  ....
  <key>name</key>
  <string>keyword.control.ruby</string>
</dict>

and put it below the entry like:

<dict>
  ....
  <key>name</key>
  <string>constant.other.symbol.ruby.19syntax</string>
</dict>

Problem

BACKGROUND: In Sublime Text and Textmate, the word "class" is incorrectly highlighted when using the new ruby hash format in a Rails link_to or form field: OBJECTIVE: Is there any way to correctly highlight the "class" keyword as it does when using the old format:

Original source