Sublime Forum

Setting region scope via a plug-in

#1

Is there a way to set the scope of a text region of a view? My plug-in wants to syntax highlight the text it generated? I don’t need to set an arbitrary color, but just set the scope of the text in a region.

add_regions() kind of does this, but the colors seem to be inverted.

I want to take a region and assign it the scope ‘string’ (for example) and have it color coded like a string in my colors file.

0 Likes

#2

That’s not possible. Two issues to look at https://github.com/sublimehq/sublime_text/issues/6381 and https://github.com/sublimehq/sublime_text/issues/817

The latter has some work-arounds we/the community uses. (The “background-trick”.)

0 Likes

#3

I just read that I proposed in-memory, ad-hoc scopes using an API e.g. register_color("git_savvy.graph.dot", {...}) (of course, register_color is semantically equivalent to register_scope). That command would basically add appendices to the currently used color scheme. I forgot about this but I think I like it a lot.

0 Likes

#4

Thanks a lot. This will work as my plug-in is only for a small group of co-workers. It’s not ideal and I hope ST adds the real function ability to set a scope on add_region(), but in the mean time this will work.

0 Likes