Sublime Forum

Mix colors for region highlighing

#1

I want to create a subtle, non-distracting region highlighting in text editor, something like that:

view.add_regions(region_id, [region], scope, '', sublime.DRAW_SOLID_UNDERLINE)

To make it non-distracting, I suppose I should mix background and foreground colors? Is it possible to pass color as scope or there’s another way to do so?

0 Likes

#2

I guess the only way (maybe ?) you can do that is to define a custom scope in your current color scheme (something that doesn’t clash with the scopes provided by existing syntax definitions for code highlighting). You can then assign a custom foreground color to it.

If you have the PackageDev package installed, you can simply select PackageDev -> Edit Current Color Scheme to get a new split window. In the rules array on the right side, you can then add a new entry.
For example :-

{
    "scope": "preferred_name",
    "foreground": "preferred_color"
}

Doing this & saving it should now give you access to the preferred_name scope (in turn giving you the access to your choice of foreground color) which can then be used as the scope argument in the view.add_regions API.

If you don’t want to install an additional package, you will need to create a file by the same name as that of your current color scheme in the User directory and then put the rules array in that & save it.

0 Likes

#3

Thanks, will try this out!

0 Likes

#4

also note there are some predefined variables available for all color schemes accessible with a region. prefix: i.e. region.redish, in case that helps, but I guess if you want to mix foreground and colors then you’ll need some extra rules in the color scheme as previously outlined in this thread

0 Likes

#5

Yes, I already use greenish scope, but I need to create universal that should work for all color schemes, that’s why I want to mix foreground and background

0 Likes