xxx
xxx

Reputation: 9104

Bundle for Ruby 1.9 hash syntax, or way to modify existing matches?

I'm working with Rails and using Ruby 1.9 in SublimeText, but it does some quirky highlighting with Ruby 1.9's new hash syntax.

For example, with the following hash, which is pretty common for rails:

<%= link_to some_page_here_path, class: "btn btn-primary" %>

The class keyword is highlighted, when it's not actually a real keyword but instead just a simple hash key. I'd prefer if it were styled as a symbol (which it is in Ruby 1.9) instead of a reserved word. This applies for the other reserved words as well, 'for', 'while', 'do', etc.

Is there a way to make this work in the existing Ruby.tmLanguage, or a tmLanguage file that already does it? Appreciate any help. Thanks!

Upvotes: 3

Views: 425

Answers (1)

Andrew Haines
Andrew Haines

Reputation: 6644

I had the same problem, so I went ahead and edited the Ruby.tmLanguage file to fix it.

You can find the definition of the reserved keywords by searching the file for keyword.control.ruby; the corresponding regex looks like

(?&lt;!\.)\b(BEGIN|begin|case|class|...|when|while)\b(?![?!])

The negative lookahead at the end (?![?!]) prevents it from matching method names like class? and class! so adding a colon to the list (?![?!:]) will also stop it matching hash keys like class:.

Upvotes: 6

Related Questions