Sublime Forum

Change color of end of line semicolons?

#1

Is there a way to make it so that semicolons at the end of the line can be a specific color? I am a bit familiar with the tmTheme files, I edited colors in one already, but I was wondering if it would be possible to add this a theme file.

EDIT: Note, I only want semicolons at the end of a line, not all semicolons (because of string operation functions using a semicolon, I don’t need those ones to stand out).

Thanks!

0 Likes

#2

You have to make a rule in your tmLanguage file for semicolons at the end of the line.
With the name of this rule you can assign a color in your tmTheme file

0 Likes

#3

Do you have any idea on how to implement that?

0 Likes

#4

IMO, syntax files are a bit of pain in the neck to edit, because they are in xml, but it must be said that they are pretty straightforward too.

This might work for your case:

<dict> <key>match</key> <string>;$</string> <key>name</key> <string>your.scope.selector.yourlanguagename</string> </dict>

Now you’d need to:

  1. Insert this snippet into the of in your tmLanguage file.
  2. Edit the scope selector with the appropriate information. To get an idea how it works, copy a selector from an element that stands out from the rest of the code (comments, error warnings, etc). Scope selectors determine how the text is styled (according to other rules you can define too) besides, well, the scope of the pattern (basically, how far it spans).

I’m writing all this off the top of my head, so YMMV, but this is the gist of it.

If you want to develop a new syntax file, you might want to try my GrammarDev package, which should let you write your syntax file in json and do the conversion into xml automatically.

bitbucket.org/guillermooo/grammardev

Order matters, etc. Syntax files can be a little tricky in the beginning.

Check out the Macromates docs for more info!

0 Likes

#5

Some small additions to the very good post from guillermoo.

  • If you insert the code in an existing tmLanguage file it might not show an effect as other entries may overlay it. I experienced this in text.tmLanguage with meta.paragraph.text (order did not matter),

  • Use ctr+alt+p to display the scope in the statusline.

  • To see results from a changed tmLanguage file I have to restart the editor.

0 Likes

#6

Do you mean end-of-line semi-colons or end-of-statement? For example, what if you do this?

var foo = "string"; // comment

Or this?

var foo = "string"; var baz = 42;

Or even this?

var foo = "multiline; string";

Not sure what language you are coding this for.

0 Likes

#7

I was working in PHP, although it would apply for many languages. If you go through your examples, each semicolon fits what I was thinking. Basically, I was thinking a way to help one find an error caused by a missing semicolon. I know I wasn’t very specific originally, but that is what I had thought. If those semicolons were obvious, it would be easy to find missing ones.

[quote=“GreyWyvern”]Do you mean end-of-line semi-colons or end-of-statement? For example, what if you do this?

var foo = "string"; // comment

Or this?

var foo = "string"; var baz = 42;

Or even this?

var foo = "multiline; string";

Not sure what language you are coding this for.[/quote]

0 Likes