Sublime Forum

Erase Region Without Key?

#1

Does someone know a way, even a dirty hack to erase highlight and gutter mark of a region without knowing the key, as required by method erase_regions? (We could all end up with a new really cool and useful plugin then! :slight_smile: )

I need a way to clear a specific line of any associated region.

  • The result should be a line without gutter marks or text highlighting.
  • I do not possess the respective key, as it is set by SublimeLinter.
  • And I also like to leave other region associated with that particular key unchanged.

The API doc does not suggest there is an inbuilt method to do this. A key as required by erase_regions
is always required and that method clears all regions without discrimination. (Also, see thread).

Background: I am currently hacking together a tiny plugin to change individual highlights from SublimeLinter.
This would be highly useful to make certain errors more discernable. Maybe give formatting warnings a color different from warnings regarding unused imports. (See SublimeLinter - Styiling individual errors possible?)

Indeed, I have already managed to highlight specific warnings/errors. Yet, the previous highlight by SublimeLinter is not overwritten. This looks ugly, as in the picture below!

Explanation: Yellow squiggly line by SublimeLinter, Orange solid line by my plugin.

0 Likes

#2

There is no such feature. All regions once added and associated with a name are tight together. The question about priority of regions arose several times in the past but was not yet solved.

The only appropriate solution was to add some kind of priority to regions, so adding regions with higher priority would automatically “remove” existing regions.

Hacking around with other packages regions causes (unpredictable) cross references and is IMO a NOGO.

0 Likes

#3

@deathaxe Thanks for your reply.

I was expecting there not to be way to achieve what I intended. Good to know it for sure know, so I do not keep pushing further into the direction.

Indeed I consider my plugin to be a mere experiment to see where it leads me on my quest for customized lint highlights. Unless something solid and reliable comes out of it I will not attempt to push it to PackageControl.

I got my inspiration from alexkuz’s plugin which accesses the regions of the active SublimeLinter instance, while not attempting to modify or erase them.

Would you say such read-only hacking with other package’s regions is OK, or a NOGO as well?

0 Likes

#4

Just reading is fine, imo.

1 Like

#5

Reading may sometimes even be required (at the moment).

GitGutter reads regions for its protected_regions feature, which avoids overwriting regions of higher priority such as bookmarks or SublimeLinter stuff.

Even though ST provides very much flexibility to handle things, but you’ll should always try to avoid cross references between packages or manipulating other’s packages data/results. This will lead to hard to find issues in the future for sure.

Each package should work as stand alone package. It might collect some information from others, but should neither rely on them nor manipulate them.

2 Likes

#6

Is there a way to overwrite a gutter symbol set by SublimeLinter?

I have now advanced my plugin to a state where I can simply overwrite the highlights set by SublimeLinter. This works beautifully. No, need to erase SublimeLinter’s regions. Yet, the gutter symbol is in some views overwritten in others not. And I do not know why it works so inconsistently.

@FichteFoll Good to know from you as the one who admits new plugins to package control, that just reading is fine!

@deathaxe I read about the protected_region feature of GitGutter. Here you speak of

overwriting regions of higher priority such as bookmarks

This confuses me as you stated prioritization is not supported by Sublime at the moment.

The question about priority of regions arose several times in the past but was not yet solved.

Could you clarify? Is there a method to indeed set priorities and overwrite gutter symbols? If so how?

Further, regarding the independence of packages. What do you say of packages specifically designed to extend other packages? Every SublimeLinter plugin relies on the core package of SublimeLinter itself. I have written a companion plugin to TerminalView. IMO as long as installation instruction clearly state the dependency it is entirely OK to rely on other packages.

0 Likes

#7

You already found the answer to that question. :wink: : the gutter symbol is in some views overwritten in others not

There is no rule how Sublime Text sorts or prioritizes the regions. If a plugin adds a region with a gutter icon to a line which already contains one it may be overwritten with the new one or not. This depends somehow on the internal order of the regions. But the order doesn’t seem to depend on region names or any other rule, and even might change.

overwriting regions of higher priority such as bookmarks

  1. You need to distinguish between:
    a) deleting regions, which were added by another plugin (NOGO)
    b) adding new regions without respect of existing regions at that line (OK)

You asked for a) which is a NOGO as it manipulates a data set created by another plugin.

The protected_regions feature addresses b). GitGutter reads out the regions listed in that key and checks each line to not contain one of them, before adding its own icons. This means if a bookmark icon already exists, GitGutter ignores that line in order to prevent the undefined behavior and “icon fighting”.

This may still cause temporary trouble if one of the “protected” plugins adds its icons after GitGutter, but it will be resolved with the next text change event which triggers GitGutter to update.

Is there a method to indeed set priorities and overwrite gutter symbols?

Unfortunately not. The protected_regions are a desperate try to implement something like that on a plugin level.

I requested such a feature some months ago.

2 Likes

#8

@deathaxe Thanks for your very informative answer!

This limitation of Sublime is really bad! :thumbsdown:

Especially since only this piece was missing to make a new and highly useful plugin to delight the community.
I will decide whether to publish my SublimeLinter CustomHighlights plugin or not.

The text foreground and background color can be changed already.
But no highlight or gutter marks in any consistent way.

0 Likes