Sublime Forum

Howto: assign custom color for custom scope

#1

Hey everyone. In the EasyClangComplete package I am developing there is a need to show highlighted errors and warnings in the code. Currently, I show all the errors by calling view.add_regions passing invalid.illegal as scope. This does the trick, but shows all the errors with a single color.

To separate errors and warnings I assume I would need to call view.add_regions two times - one for errors and one for warnings with different scopes passed into the calls.

Looking at http://www.sublimetext.com/docs/3/scope_naming.html I did not find any scopes I could use directly, so it seems I would need to define my own scopes. So to this I have basically two questions:

  • passing the new scope, e.g. entity.warning and entity.error into view.add_regions is all that I need to define custom scopes? No need to define a syntax file, right?
  • how to generate custom colors for my custom scopes? Can I setup a very small color scheme to cover only the scopes I care about and distribute it with my package or is there another way? Would the scoped not defined in this small scheme be picked up by another color scheme?

Some related issues that did not help me much (but maybe I have just misundestood them):

  • 35200 - leads to the scope naming website referenced above with a hint to use the existing scopes, which is not exactly the use-case I’m targeting as I don’t intend to provide a complete colorscheme.
  • 33019 - also leads to the scope naming website with approximately same suggestions.
  • 18842 - an old issue that is very related to what I am asking here, saying its impossible to do what I want to do without modifying an existing theme file, so I was wondering is there is any change since then.
2 Likes

#2
1 Like

#3

Thanks! Do you have more context on this? While definitely a useful issue to know about it still seems to be open.

1 Like

#4

Bump? Anybody?

1 Like

#5

Well, the short version is that the proposal hasn’t been accepted or reviewed by wbond (or another st dev) yet, although community members seem to have reached a consensus mostly. Note that this is not reflected in the OP.

1 Like

#6

Hi, this is basically what I do in my plugin (Word-highlighter):

  • A minimal color scheme exists in the plugin (a template). This color scheme only contains the rules with scope definitions that I need for my own highlights. When the plugin is loaded, the template is copied and renamed to the current color scheme (e.g. “Mariana.sublime-color-scheme”) so that it is parsed and used by Sublime text.
  • In the plugin, the highlights are created using the view.add_regions command, with the scope names that are defined in the color scheme.

The template color scheme from my plugin.

2 Likes