Sublime Text 2 highlighting : how to differenciate variable declaration and variable use?

Issue

Is there a way to differenciate variable declaration and variable use by using two different colors with Sublime Text 2 syntax highlighting ?

Here is an example of what I’m trying to do : (screenshot from jsFiddle)

enter image description here

I didn’t find anything helpful in any of the Sublime Text 2 color schemes xml files and on the web either. Is what I’m trying to do even possible ?

Solution

This is only possible if the syntax definition scopes the variable declarations differently to the uses. The JavaScript syntax that ships with ST doesn’t do so.
Therefore, unless you alter the syntax definition, there is no way to change the color scheme to achieve what you want.

If you upgrade to ST3, you could update the syntax so that after it scopes the var keyword, it could push into another context where it would expect an identifier, and scope that uniquely. See the sublime-syntax documentation for details.

Answered By – Keith Hall

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.