Sublime Forum

Easy outline, underline, or nondestructive region marking

#1

I’m trying to stress some regions in any file opened with a certain syntax highlighting. The regions are already identified with a certain meta scope. I’d like to make reddish / purplish / etc. outlines around these regions, and update them as you type.

Do I need companion Python for that? I tried putting region.reddish in the syntax definition itself, but it’s a little heavy-handed and probably unreadable for certain color schemes.

1 Like

#2

You could add a color scheme rule to match that meta scope only when it appears in the syntax of your choosing, and then the color would only apply to that specific color scheme. If you swap color schemes that requires more setup work though. If you’re doing something that you intend to share with others, that adds more complications as well.

If you want to do an outline or underline of the text then I think the only way to pull that off is with regions, though, and for that you’d need a plugin. Trivially you’d write a function that applies a region to the scope you want and then invoke it from an on_load_async and on_modified_async event handler.

As long as text is edited inside of the region, the boundaries will adjust automatically (and they’ll move if the text around them is shifted). However wholesale replacement or additions to the beginning or the end won’t be included automatically.

I don’t think you can use the -ish colors in the view.add_regions() call though; I think you can only use scopes in that position. Assuming I’m remembering that correctly that adds its own wrinkle for determining what scope has the color you want.

2 Likes

#3

You can use colorish scopes with view.add_regions(). The only known place where you specifically can’t use them, are color schemes themselves.

That said, if you wish to provide “subtle” highlighting like with an outline, you must use a Plugin, as @OdatNurd said.

If you’re fine with targetting a single color scheme, you may also specify a background color for your meta region with that scheme. And yes, you may use color.redish in your syntax definition as well. If that dosn’t look good as a foreground color, then it’s most likely on the scheme developer to fix that, because this is one of their intended uses. If your stressed region is related to some markup, e.g. build output, you might also be interested in one of the suggested markup scopes like markup.error and solidify its use by prepending a colorish scope first as a fallback for color schemes that do not provide this, i.e. color.redish markup.error.<whatever>.

2 Likes

#4

Thanks. I’m making a PR to Crontab which was using arbitrary scopes to simulate column highlighting. (Minute = string, hour = keyword, etc.)

I dropped those scopes in favor of semantic scopes on the elements of the cron expressions, but I can see how someone might consider it a regression. I am hoping that a colored outline for each of “minute, hour, etc.” would be a suitable replacement.

Also, now that I think about it, I could make hovers with syntax hints or parser output. (I tend to consider cron expressions to be tedious to write and nigh impossible to read.)

I’m going to take a look at the official example plugins, but if someone else has a package you think would be useful to check out, let me know.

1 Like