andrescabana86
andrescabana86

Reputation: 1788

Adding syntax highlighting to Sublime Text for JavaScript

i have a single problem, in my sublime text 2 the syntax highlight of javascript takes this code

this.init = function(){};
this.init : function(){},

painting of "this" in lightblue and "init" in green...

but in this case...

this.init = null;
this.init : null,

is not happening... i want to highlight "this.*" in all cases of use...

like for example

this.init = function()
this.init : function()
this.init : true
this.init = true

how can i do that???

Upvotes: 0

Views: 4767

Answers (2)

MattDMo
MattDMo

Reputation: 102842

Adding to ben336's answer, I tested your code with my Neon Color Scheme and a few different JavaScript language definitions, including JavaScriptNext, which actually did look the best:

this.init with Neon theme

The scopes for the init method are interesting (all are source.js, of course) -

this.init = function(); // meta.property.js variable.other.property.js
this.init : function(); // meta.function.js meta.function.json.js entity.name.function.js
this.init : true; // meta.function.js constant.other.object.key.js string.unquoted.label.js
this.init = true; // meta.function.js meta.property.js variable.other.property.js

Since the last 3 are function scoped they should be colored bright green, but the third one has a string scope and the last one a variable.other scope, so they pick up those colorings instead.

If you'd like, I can try to finagle the theme's function scope selectors to color the last 3 consistently - just open an issue or let me know here and I'll see what I can do.

Upvotes: 0

Ben McCormick
Ben McCormick

Reputation: 25718

The default syntax highlighting for javascript in Sublime is not great.

I use JavascriptNext: https://github.com/Benvie/JavaScriptNext.tmLanguage

It improves on the default syntax hightlighting and also adds support for future ES6 syntax.

In your particular case it is more consistent on the coloring of the if values, though less consistent on the property values for the : syntax. But I think thats ok since its not actually valid syntax anyhow.

Comparison

Upvotes: 6

Related Questions