Sublime Forum

Creating theme for custom scope on the fly

#1

Hi,

I’m working on a plugin that uses view.add_regions(…, …, scope,…) to add visual information, where I would like to use a “scope” name which would not present in a standard theme file. The only way I know to make this work is to have the user of the plugin edit his/her favourite theme to add the appropriate information. I would like to do this in a more flexible way as follows:

if the scope name is defined in the theme file [1], use it, otherwise “create” such a scope programmatically - something like:

if scope_exists(scope):
view.add_regions(…, …, scope, …)
else:
view.add_regions(…, …, my_scope, …)

where my_scope is a way to assign a given foreground colour. [2]

I have no idea if it is possible to do (in a plugin) either [1] or [2] or both… but it would be really nice.

Any ideas?

0 Likes

#2

It’s not possible, and I’m not sure how it could work - without knowing the background color of the theme the user is using, how could you ensure that your color would be different?

I suggest using a common scope, and adding your own suffix, such as “invalid.lint_error”, which will allow your region to have a default color for most color schemes, but still allow a color scheme to assign it a specific color.

0 Likes

#3

I was thinking of then giving the option of setting this color via a user-set preference - which is something less of a burden to ask of a user than modifying a theme.

[quote=“jps”]
I suggest using a common scope, and adding your own suffix, such as “invalid.lint_error”, which will allow your region to have a default color for most color schemes, but still allow a color scheme to assign it a specific color.[/quote]

Thanks; that’s what I will do.

0 Likes