Sublime Forum

Build result highlighting

#1

Howdy,

I’m currently developing a plugin that occationally outputs messages in a custom panel. As there might be multi-line messages involved and I could not come up with a ‘‘result_file_regex’’ that matches such messages, I’m using custom code to perform the highlighting.

It works great, but I’m now facing the (cosmetic) problem that I don’t know which scope name to use for the add_region function to match the color used by the default build results highlighting. Therefore whenever I’m using F4/Shift F4 to step through the messages, I end up with different coloring for the first line vs. the rest.

I’m attaching a screenshot for illustration. F4 causes the first line to be highligthed in blue, and the rest is highlighted in black (using custom code) but it should rather use the same blue as the first line.

The API doc only lists ‘string’ and ‘comment’ as possible values, and I could not find any information about other scope names, but it surely should be possible to use the standard build output color as well.

I’m speaking about this function:

sublime.View.add_regions(key, [regions], scope, <icon>, <flags>)

I would appreciate any input. Thanks in advance.

Cheers,
Marco


0 Likes

#2

It would be nice if the text on the screenshot was actually readable.

Anyway, it seems to me that you are having problems making “result_file_regex” of an output panel match a multi-line string and you are using view.add_regions to colorize the background of the remaining parts of the match. The f4 and shift+f4 commands do not use a “scope” for their highlight, they make a selection. Thus, by colorizing more stuff with the same color you would just have to extend the current selection of it. You could hook into “on_selection_modified” and check for some internal view id to only modify the selection on your output window.

As for the “result_file_regex” multi-line issue: Did you try matching any of “\s\r\n” or “.” with “(?m)” (probably “(?s)” but test both)?

0 Likes

#3

Exactly!

Interesting. It didn’t come to my mind to alter the existing selection. I will try that and it hopefully solves the issue. Awesome!

I’ve tried different approaches and yes, I’ve experimented with multi-line matching - (?s) is the embedded expression needed here - but I was not able to come up with a regex that matches just one multi-line message. Not sure whether I did something wrong or the stingy quantifiers don’t work my way. I always ended up with the rest of the output panel text highlighted, not only the rest of the current message highlighted, therefore the workaround with custom code.

Thanks very much for your help! Awesome project BTW. Kudos to the developer!

0 Likes