Sublime Forum

BracketHighlighter2 BETA Branch

#95

So then how do I use the existing non-dynamic approach? I’m not sure I fully understood what you were getting that, then.

0 Likes

#96

Take a look at the current settings. I only define one color in default. The rest of them inherit that color. You can see I have colors commented out in the others. If you uncomment them (and the scope actually exists) those style definitions will pick up the new style. The easiest way to understand is to take a look and turn some of those knobs.

It is the eternal problem of not giving people enough knobs to turn vs giving them too many. People wanted it to be configurable for every thing they wanted, the down side is that now you have to turn all of those knobs to get what you want :smile:.

0 Likes

#97

Can you define the defaults when something isn’t specified in the User settings file?
For instance, when I do this in my user settings:

{ "bracket_styles": { "unmatched": { "color": "brackethighlighter.unmatched", "style": "underline" }, "curly": { "color": "brackethighlighter.curly" }, "round": { "color": "brackethighlighter.round" }, "square": { "color": "brackethighlighter.square" }, "angle": { "color": "brackethighlighter.angle" }, "tag": { "color": "brackethighlighter.tag", "style": "underline" }, "single_quote": { "color": "brackethighlighter.quote" }, "double_quote": { "icon": "double_quote", "color": "brackethighlighter.quote" }, "regex": { "color": "brackethighlighter.quote" } } }
All the icons are the circle except the double_quote when I manually copied in. Shouldn’t this be falling back on the default values for that particular setting when I don’t specify what I want?

On a side note, I guess there’s no easy way to simply grab the coloring of the outermost character highlighted/underlined/outlined/etc to use. Oh well. :frowning:

0 Likes

#98

I explain this in the settings file.

[pre=#151515] // “default” and “unmatched” styles are special
// styles. If they are not defined here,
// they will be generated internally with
// internal defaults.

    // "default" style defines attributes that
    // will be used for any style that does not
    // explicitly define that attribute.  So if
    // a style does not define a color, it will
    // use the color from the "default" style.
    "default": {
        "icon": "dot",
        "color": "brackethighlighter.default",
        "style": "underline"
    },[/pre]

If you do not define the default style I define one internally.

Attributes from “default” is what gets used when you don’t define an attribute in another style. So in your example, you did not define an icon, so the default one got used. But you also did not define a default style, so the plugin used the internal one which defines the icon as “dot”.

I don’t understand what you are expressing here. See the above response which explains the behavior. It is acting as intended.

[quote=“Gnintendo”]
On a side note, I guess there’s no easy way to simply grab the coloring of the outermost character highlighted/underlined/outlined/etc to use. Oh well. :frowning:[/quote]

It could be done, but it causes a lot more complexity to an already complex set of rules. Take a look at the actual code, you will see to make it as configurable as it is now, there is quite a bit of complexity. What you propose would require yet another exception, and impact a lot of code. It would require me to dynamically create a region for each individual bracket opposed to bracket groups as it is done now. And if I added it, someone would then not be satisfied that it picks the first scope, but want maybe the last scope etc…I don’t want to open that box. But I do appreciate the feedback. Certain features I push back on because I have to maintain this code, so no offense :smile:.

0 Likes

#99

Thanks for the update! Just finished migrating my old settings, no biggie, like 10 minutes of work (i think 8 minutes took to figure out how new stuff works :smiley: )

Few stuff:

  • it is possible to extend a theme? I mean ok, i changed Monokai, but what if there is a new version of Monokai in the future? (is totally unrelated to BH, it’s more related to ST itself).

  • i noticed that if i would remove everything and let this empty in my user bb_core settings file:

"scope_brackets": ]

Highlights stops for quotes. If i remove completely, it’s fine (which is what i did). I’m not customizing anything in this area (not now, probably not ever), but probably it’s a good idea to have an option to merge settings with default or just replace completely. That’s because it’s kinda silly to copy/paste ALL default settings just to add one more setting. Again, i’m not using this, but probably someone that use it should provide some feedback.

  • i read in another thread about alpha colors. Which i tried and works awesome. There are some situations when text cursor it’s slightly hard to see (when you use style:solid). I was thinking of adding an option to „dim the solid color” when you are touching a bracket with the cursor ( like so {|} ). In this case, if the color is #CC0000, when touching would be #CC000066 or something like that. Make sense?

  • another thing that may be useful (ask other users too!) is to not highlight brackets that are touching ( e.g. in: function(){ }, () part should not be highlighted, but {} should be)

Pfiew, that’s all for now. I woke up in a typing mood! :mrgreen:

0 Likes

#100

Not sure. I don’t think you can, but I could look into it. I usually copy my color schemes to a sub folder in my user folder so ST2 will not overwrite my personal edits.

Yeah, that is how ST2 loads settings files via sublime.load_settings. If I do a custom deep merge solution, I have to start watching files for changes and reload etc. like ST2 does…it is not really worth it. ST2 already does all of this, it just does a shallow merge (the user key overwrites the base key), just something you have to be aware of.

Makes sense. I would do this if ST2 would only directly accept a color via the API, but since it doesn’t, the only way to accomplish this is to require the user to make a separate dimmed color profile, and based on some internal rule pick between the two color profiles.

I could do this if enough people wanted it. Basically you want to ignore a bracket if the two brackets touch each other? The only issue I see though, is that it might be annoying for some types of brackets. For instance, tags have bracket plugins that allow you select the tag names of both opening and closing tags so you can edit them both. So if you created a tag, but you decided to change their name (and the tags touched), the plugin wouldn’t work. Anything I do, I want to make very general so it works with all brackets. I don’t want to hard code things specifically for tags etc. Also things like swap tags would break etc. (I know it isn’t working right now, but when I finish it, it would break on this for touching brackets).

0 Likes

#101

Cool, thanks for explanations. :wink:

0 Likes

#102

I kinda found another bug! :mrgreen:
So, let’s say we have this snippet:

          <?php for ( $i=0; $i < 5; $i++ ) { ?>
            
          <?php } ?>

The bug is that { and } doesn’t highlight correctly (only as invalid), although if I press ctrl+m (to jump to pair bracket) will jump correctly.

This is not related to my custom settings of the plugin (i removed everything and act the same).

0 Likes

#103

[quote=“iamntz”]I kinda found another bug! :mrgreen:
So, let’s say we have this snippet:

          <?php for ( $i=0; $i < 5; $i++ ) { ?>
            
          <?php } ?>

The bug is that { and } doesn’t highlight correctly (only as invalid), although if I press ctrl+m (to jump to pair bracket) will jump correctly.

This is not related to my custom settings of the plugin (i removed everything and act the same).[/quote]

Mine highlights “{” and “}” as invalid (which I would expect, since “{” and “}” are not matched between the “<?php ?>” tags, it breaks the valid match rules). And cannot jump between the “{}” brackets either because they are invalid. This is the case for ctrl+m and BH2s jump between brackets method for me as well. ctrl+m uses ST2s algorithm. BH2 uses its own. I provide example keymaps to use BH2’s version.

Now Ctrl+m was able to match PHP angles in the last PHP group, but not in the first. BH2’s match did not match either. BH2 is very consistent when using its algorithm. ST2 seems like it is not.

Are you able to post more code? Because I could not reproduce what you described with just what you posed above. As you can see my description seems different than yours.

0 Likes

#104

There is no need for more code because it seems that everything that match follow this pattern (more or less) doesn’t work:

< { > 

< }>

I made a short movie here:
(http://img.iamntz.com/jing/2012-11-04_1918.swf)

with settings off (including those PHP tags):
(http://img.iamntz.com/jing/2012-11-04_1924.swf)
(also, at the end of the movie i enabled my settings & tried to use other brackets)

Green is ok, red is invalid. Pink is… i have no clue what (or why) is pink in that context!

0 Likes

#105

Pink is invalid syntax (sytax highlighter; not plugin related).

I am still confused. If I showed you this, I think we would both agree the curly should not be matched because what you really have is two broken curly pairs. This is invalid bracket pairs.:

({)(})

This should match fine:

({})({})

What you are showing me is the equivalent is it not?

<?php { ?><?php } ?>

or

<{><}>

Everything is generalized in BH2. It starts matching pairs and resolving them until it comes to the closest one surrounding the cursor. Isn’t this what it is doing? You just have (by the generalized algorithms view) dangling curly brackets between valid angle brackets.

Now what you are wanting is some special case for PHP (which makes sense), but keep in mind BH1 couldn’t resolve these issues either, and ST2 doesn’t resolve them well either (if at all). HTML tags don’t have this issue because they are a special case. In HTML, we just find the surrounding angles (which will always be a valid match if the tag is formatted correctly), and if they are part of a tag, we search the buffer for tags only (this is why it doesn’t get confused resolving other brackets in between). But this is done with a special post_match BH plugin.

Here is another case that BH2 cannot resolve (C/C++ code). Which opening curly should it match to the closing?:

#if (SOME_SWITCH)
if (some_condition) {
#else
if (some_other_condition) {
#endif
    dosomething();
}

There are some cases that BH is not going to be able handle very well. And the amount of code to tackle these issues can be quite a bit. Now PHP might be able to be resolved much easier than the C problem. I won’t touch the C problem at all. But maybe in the future I can come up with a PHP solution (maybe).

Now in regards to ctrl+m finding different brackets than BH, this is because ST2 uses a different algorithm than BH2. I can make the “jump between brackets” BH command work more like ctrl+m, but it will still be using BH2’s algorithm to match brackets. Currently BH2 has two separate “jump between brackets” commands. One jumps left, the other jumps right. ST2 just toggles between the two.

0 Likes

#106

[quote]This is invalid bracket pairs.

({)(})

[/quote]

Agree, but there are some languages (PHP, probably coldfusion) that are using this kind of stuff (loops, conditions) mixed with html code.

This make the plugin or the editor less awesome? Hell no! Is just a thing that would be nice to have. If is too much trouble, let it go, focus on more important stuff, i will survive. :smiley:

Btw, as a totally non-related thing, i just realized that most used addons to sublime are: Soda theme, BH and emmet/zen. :mrgreen: :geek:

0 Likes

#107

I agree. Better PHP support would really be nice to have. It is one of those things that I have stored in the back of my mind to hopefully resolve some time. Sadly it is not on the top of my list. I really have only two maybe three things left I need to get knocked out. As you can see by the recent lull I have been taking a little break after the non-stop BH code-athon. I needed to step away from it for a little. Especially since it seems pretty stable, I felt okay about that. I have been side tracked by a couple of side projects.

The last things I have on my list are:

  • A reasonable way to swap brackets (specifically swap out what gets highlighted with something else), with some functionality similar to wrapping (definable regions to highlight, and definable tabstops)
  • Possibly a way to define a sub bracket search to only be searched of a scope (someone made a request to search php strings for HTML tags and I am looking into allowing certain non-scope brackets to be defined that are only searched for inside scope-brackets - such as strings).
  • xeno-by’s request to have a high visibility mode
0 Likes

#108

// dreaming mode: on
Don’t know if you ever saw xcode bracket highlight, but when cursor touch a bracket, both brackets will kinda… jump (you can see it in action here). Sure, Xcode is dumb and will only do this then stop highlight at all (unless you touch again brackets), which kinda sucks.

Also, when you hover the bracket on the gutter, will sort of fade out the content of the outer brackets (here).

Not a big Xcode fan (in fact i hate it) but i think it’s the nicest thing that anyone can [size=50]steal[/size] pay tribute to (because, we all know, apple never steals, they only pay tributes!) :smiley:

I’m pretty sure that these are some limitation of ST, that’s why i used dream mode :mrgreen:
// dreaming mode: off

0 Likes

#109

[quote=“iamntz”]// dreaming mode: on
Don’t know if you ever saw xcode bracket highlight, but when cursor touch a bracket, both brackets will kinda… jump (you can see it in action here). Sure, Xcode is dumb and will only do this then stop highlight at all (unless you touch again brackets), which kinda sucks.

Also, when you hover the bracket on the gutter, will sort of fade out the content of the outer brackets (here).

Not a big Xcode fan (in fact i hate it) but i think it’s the nicest thing that anyone can [size=50]steal[/size] pay tribute to (because, we all know, apple never steals, they only pay tributes!) :smiley:

I’m pretty sure that these are some limitation of ST, that’s why i used dream mode :mrgreen:
// dreaming mode: off[/quote]

There are a lot of things I would love to do if the API would let me. Sadly it won’t let me do everything I would like.

The second demo is essentially what xeno-by wants. I can’t do it like that though (regions sizes are limited by actual code text, so no perfect boxes, just text regions, and it kills syntax highlighting when with the region overlaid; also, can’t trigger on hover events, so must make a toggle keybinding etc.). But if you really want to briefly use a high visibility mode, I can see how it would be useful which is why I have it on my list.

0 Likes

#110

Update:
-Added high visibility mode (a mode that can be toggled to make bracket extent clearly visible). Essentially it just highlights the entire bracket block. It isn’t meant to be run all the time, mainly just for times where you really need to see the extent of the the bracket block very clearly.

An example done in different styles.

High visibility mode uses one highlight style for all brackets, but it inherits the brackets icons, and can optionally inherit the color as well.

The other update is one that will affect your settings file. I changed the find_in_sub_search in the bracket definitions to be a string variable instead of a boolean. So do this to all of the bracket definitions in your User settings file if they have this setting:

[pre=#151515] // Change this
“find_in_sub_search”: true,

// To this
"find_in_sub_search": "true",[/pre]

Now find_in_sub_search can be set to “true”, “false”, “only”.

BracketHighlighter is officially bumped to BETA status. There should be no more settings format changes now that this is in BETA.

The last and only feature on my list is the bracket swapping.

0 Likes

#111

Loving this!! Thanks for all of your hard work Isaac!

0 Likes

#112

Thanks :smile:.

0 Likes

#113

Having recently started writing Clojure in Sublime, I’d like to thank you for this plugin :smile:

0 Likes

#114

Clojure, eh? I can see why this would be helpful :smile:. Glad I could help make your task a little easier.

0 Likes