Sublime Forum

Custom highlighting

#1

Hello,

I’m using a slightly modified Monokai theme.
I was wondering if there is a way to specify custom strings in particular language scopes to colour in a certain way.
For exampe:

JS: I want ‘use strict’; to be highlited.
JS: this keyword should have a different colour. I can colour it by updating the variable entry, but that colours all vars in all languages
PHP: highlight <?php and <?= and ?>

Is there a way to do that in tmTheme files?

Thanks.

0 Likes

#2

I’ve managed to do that creating a copy of Monokai and editing it.
Then changing the language definitions so that this falls into a different category than variables in JavaScript for example.

But this is a hack.

0 Likes

#3

[quote=“Francisc”]I’ve managed to do that creating a copy of Monokai and editing it.
Then changing the language definitions so that this falls into a different category than variables in JavaScript for example.

But this is a hack.[/quote]

Unfortunately, this is what is required. You have to amend the tmLanguage definition file to give ‘this’ and ‘use strict’ specific scopes, then modify your theme file to colour these scopes.

But you need to be careful where, and how, you place these new scopes in the language file, as it can potentially break other scoping/colours around these terms. If you don’t wish to study the definition file - which is quite a big job! - you’ll need to use a bit of “intelligent guesswork”. Unless someone else might offer specific instructions for you.

Perhaps just include ‘use strict’ with the word debugger:

<dict> <key>match</key> <string>\b(debugger|use strict)\b</string> <key>name</key> <string>keyword.other.js</string> </dict>

0 Likes

#4

Yup, good idea. Thanks.

Should be much easier to allow for user-defined colouring.
It’s not even all that difficult.

0 Likes