简体   繁体   English

如何在Sublime / Textmate 2中更正用于设置Rails链接或表单字段“class”的语法高亮显示

[英]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: 背景:在Sublime Text和Textmate中,在Rails link_to或表单字段中使用新的ruby散列格式时,“class”一词被错误地突出显示:

在此输入图像描述

OBJECTIVE: Is there any way to correctly highlight the "class" keyword as it does when using the old format: 目标:有没有办法正确突出显示“class”关键字,因为它使用旧格式时:

在此输入图像描述

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 . 因为ruby的关键字与“class”匹配,所以它试图突出显示它就像你有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. 如果编辑Ruby.tmLanguage文件(在Packages / Ruby中),可以在定义新ruby 1.9哈希语法的部分下面移动定义关键字的部分。 That way it should prioritize the new hash syntax. 这样它应该优先考虑新的哈希语法。

Look for a <dict> entry that contains: 查找包含以下内容的<dict>条目:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM