Sublime Forum

Documentation on syntax coloring?

#1

How would one go about changing/adding syntax colors for a particular syntax? I’ve taken a look at http://sublimetext.info/docs/en/extensibility/syntaxdefs.html?highlight=color but while that has information about defining the syntax rules, it doesn’t have much information about changing colors themselves.

From what I gather, the syntax definition parses out the file into it’s constituent semantic tokens and then those tokens are colored in the color-scheme file? Is that correct?

I ask because I’m taking a look at the restructuredText highlighter which, well, doesn’t highlight much. It would be nice to add colors to sections, lists, directives, etc. How would I go about doing that? The reStructuredText.tmLanguage already seems reasonably complete, but still no colors.

I also wouldn’t mind contributing to some documentation on how to go about this activity.

I’m running a b2144 x64 build on Win7.

Thanks

0 Likes

#2

Syntax definitions (.tmLanguage) establish the rules to break up a document into scopes. Each of those scopes is assigned a scope name. Syntax definitions don’t do anything else. Color schemes, defined in separate files to syntax definitions, provide the “style” for each scope name. Scope names are arbitrary, so color schemes cannot target every possible scope name, but instead usually limit themselves to a set of well-known scope names that exist by convention. All that means syntax definitions as well as color schemes are required for the code highlighting to work. Unlike color schemes, however, scopes are useful on their own for many other purposes (like snippet and plugin intelligence, etc.).

From the above it follows that if one uses unconventional scope names in a syntax definition, the color scheme will have to be edited if you want them styled. Otherwise, you can get a more colorful highlighting for a language by simply improving its syntax definition and adding more (well-known) scopes. In the case of the reST syntax definition, I think it’s rather basic, it just defines a handful of scopes, and I believe some of them aren’t even styled in any color scheme.

Also, Sublime Text stores all these files in an XML format and it’s ugly…

0 Likes

#3

I made a theme for myself, I copied a .tmTheme file from the color-scheme folder in the appdata/roaming/sublime text 2/packages directory. I renamed the file to whatever theme I wanted to call it (keeping it in the color-sheme folder). I then opened the file in sublime text and renamed the title of it in the xml (very near the top). I just sat down with a HEX color picker (http://html-color-codes.info/), typed out some python code that used all the different syntax scopes, and started changing the hex code for each scope to see what happened. After you make a save to your .tmTheme, to see the changes you have to switch to a different scheme in sublime text and then back to your saved one. The python syntax scopes are the first ones you can change in the xml file. Trial and error until you’re happy with something.

0 Likes