Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

enter image description here

OBJECTIVE: Is there any way to correctly highlight the "class" keyword as it does when using the old format:

enter image description here

like image 329
neon Avatar asked Nov 26 '12 14:11

neon


1 Answers

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>
like image 153
Shadwell Avatar answered Oct 21 '22 00:10

Shadwell