Sublime Forum

BracketHighlighter 2 Moar Bracket Powa!


Might be useful if easily togglable.



I don’t think that would be a problem. If you could put in a feature request on github, that will help me remember to look into this. Right now I am focusing on some core stuff.



Where do I need to save this to enable Ruby matching?



Where do I need to save this to enable Ruby matching?[/quote]

It only exists on my computer right now :smiley:. I am trying to find people willing to test when I have a more solid test branch. If you are interested, I will let you know when I have a branch up.



BH2 is coming along nice. It can now match the basics like {}, ], (), <>, and tags. You can also define custom pairs. It can find like brackets such as “” or ‘’ if they are part of the same scope. You can also define custom pairs of these as well.

All matches are currently performed when the cursor is between the brackets. The old version would allow you to touch the outside of a bracket with the cursor; this functionality does not currently exist, and probably won’t on initial release (if at all; it would really depend if enough people called for it down the road).

In general, the search time for brackets matching is more flat with a given threshold in the new version. The old way, the bracket match was quick when the brackets were close, and much slower when they were further away. Increase the threshold, and really far brackets were really slow. The new search method is quicker for further away brackets, but it is more flat. Close brackets and far brackets search time is not so so drastic anymore. If you increase the threshold on the new version the whole range slows a little, but comparing a threshold of 4000 between old and new, the new is much faster on average than the old.

I know this might not make since, but in short, on average, BH2 matches brackets faster and it is more configurable for almost any “bracket” pair you want. Basically you will be able to increase your threshold and search further and it still feel like it did on lower thresholds in BH1.

I have also added functionality that will wrap a given selection with any bracket pair you want. You can even configure it to indent etc. So if I had some C code and I wanted to but an #if/#endif switch around it, BH2 would block it off and surround it with the brackets. If I had some Ruby code and wanted to put a if/end conditional around a selection, BH would wrap the selection and indent the content (if defined to do such). You would then have to define the actual condition, but the if/end would be wrapped around it. Its pretty basic, but useful.

I have most of the supplemental plugins ported over for use in BH2 (assuming I don’t change how plugins are defined again). So things like jumping between the two bracket ends, folding by brackets, swapping quotes, swapping brackets, etc. is working (some of the tag stuff not yet).

I still have some stuff to work out though. Currently I don’t have searching of brackets inside strings enabled yet, I have to figure out if I want to just allow basic bracket searching via an external plugin, or allow some kind of recursive bracket matching inside scope bracket matching. And other stuff. I am sure even after the beta, it will need some refining, but good progress has been made.



Looks like I should have an alpha out within the week.

-It now can match almost any unlike brackets you define (think {}, ], #if/#endif, etc.)
-It can find most any like brackets you define if they are contained in the common scope. (think quotes, etc.)
-If you have a matched scope type bracket pair, you can also find sub brackets (think finding (), {}, etc. inside quoted strings)
-You can wrap selections with brackets of your choice, even slightly less brackety things like #if/#else/#endif and it will properly indent all elements added.
-You can remove simple brackets so anything thing with only a start cap and or an end cap, (think {}, ], #if/#endif…but not #if/#else/#endif)
-When wrapping brackets you have the content blocked off, or blocked and the content indented
-You can swap brackets. It replace them inline no formatting. But it can do things like turn a #if/#endif into a #if/#else/#endif and indent the extra item.
-You can swap quotes and it will take care of proper escaping of quotes inside the string.
-It can jump between bracket end caps.
-It can select content between brackets.
-Fold the bracket content.
-Find tags.
-Select tag names in both the opening and closing tags for quick and easy changing.
-Jump between opening and closing tags, and jump between tag attributes.

So a lot of stuff it could already do, but some new stuff as well. The big thing being a increased performance (based on the testing I have done so far), and increased configurability so people can finally configure any bracket they want. Also the new wrap brackets around selection feature.

The last thing I need to really figure out is how to properly take care of specific cases such as strings where you don’t want to find escaped brackets in a regex string, just the unescaped brackets. Because everything is so generalized now (so people can define the matching for anything), I am trying to think of a generalized way to define this so I am not hard coding it and interfering with scenarios where this is not desired.

But anyways, things are looking pretty good. Hopefully testing can begin in this next week.



Just wanted to say, I am looking forward to this plugin, and using it. :smile:



Thanks! I have been avoiding the re-write, but I know a lot of people have wanted more flexibility. Hopefully this will live up to people’s expectations; it has been a lo of work :smile:.




Thanks! I have been avoiding the re-write, but I know a lot of people have wanted more flexibility. Hopefully this will live up to people’s expectations; it has been a lo of work :smile:.[/quote]

I hope so too. :smile: I’m sure I’ll use it though.

Just a question, I still can’t understand exactly what this plugin is for… I understand it’s to customize the way brackets etc. light up, depending on your settings, is this right?



This is a re-write of BracketHighlighter. Originally BracketHighlighter was written by Pyparadigm (it was called something else though). Anyways, I increased performance on it and added a number of features which never got pulled in, and eventually Pyparadigm removed his original package.

BracketHighlighter used the core algorithm that Pyparadigm put in place, but it was limited to {}, ], (), and tags (which triggered off of <>). It was very specific and not very flexible. I was able to squeeze in quotes, but it was all hard coded. I kept getting requests for other types of brackets or bracket like matching, but the algorithm could not support it easily at all.

So, I was left with telling people I could not support their request, or re-write the algorithm to support it. A complete re-write is a lot of work, so I have put it off for quite a while. This is what BracketHighlighter2 is. BracketHighlighter 2 is a complete re-write that allows users to configure automatic matching of whatever they need. Quotes, brackets, #if compiler switches, ruby if/end blocks, CSSEdit @group stuff, tags, and whatever other bracket like matching that is desired with minimal effort from me or the user. Now you can just define the rules in the settings file, and BracketHighlighter 2 will take it from there (really tricky stuff can tap into bracket plugins to accomplish the task).

An added benefit is the algorithm is seems faster overall.

In short BracketHighlighter 2, if all goes well, is meant to be the successor of BracketHighlighter; it will replace the old BracketHighlighter. Hopefully, everyone will like it much more. As long as performance for everyone is as good or better, this will be the new version. Which is why I need people to test it and real feedback. It is meant to be BracketHighlighter, but more configurable and faster.



OK, that makes it very clear. :smile:

Whenever you get the beta out, you can count on me, just send me a PM. :wink:



[quote=“Eduan”]OK, that makes it very clear. :smile:

Whenever you get the beta out, you can count on me, just send me a PM. :wink:[/quote]

Will do. I should have a beta out this next week. BH2 now does everything the old one did (except for maybe one or two minor things I have removed for now). I plan on tweaking the code for the new feature of wrapping brackets around a selection, and then I will create a testable branch.



Awesome! Looking forward to it. :smile:



Love that you’ll allow custom bracketing definition… that’s killer. Count me in for testing!



@SeanWcom Thanks!



Preview of BracketHighligheter’s new wrapping feature.

I have always wanted a nice easy way to wrap selections with custom stuff. I just wanted for instance to select some text, and select a something to wrap it with: tags, brackets, compiler switches, other stuff.

ST2 does good with brackets, but so much with other stuff. So one of the things I wanted to do in BH2 was to add this kind of functionality. I wanted to be able to define starting selections, tabstops, and indent style if required.

As you can see, the first example wraps a function with a compiler switch in C. It has two tabstops, and it is blocked off when the wrapping occurs.
In the second example, we have some HTML code, that gets wrapped in a generic tag with two tabstops that both automatically get selected so you can change their name a the same time. Also it blocks off the content and indents it.

This can be applied to lots of stuff. Something I am starting find pretty useful.

Still have some stuff to work out on bracket swapping which might end up being a more simplified version of this. Swapping won’t auto indent etc, it will just replace the brackets inline. So you could turn curly brackets to square, or turn an #if/#endif condition into a #if/#elseif/#endif leaving the conditions in tact. I might add tabstops and auto selections to swapping as well. I think once I update the swapping stuff, I will setup the branch. I didn’t intend wrapping and swapping to turn into what it did…it just kind of did…so this will set me back a little. Wrapping is done, I just need to rewrite the swapping stuff.



That is totally awesome facelessuser!

I suppose you are going to allow us to customize these automatic bracketing correct?



[quote=“Eduan”]That is totally awesome facelessuser!

I suppose you are going to allow us to customize these automatic bracketing correct?[/quote]

Of course. The last thing I want to do is have people making requests to me for doing this in every language :smiley:.

So everything is generalized. Here is an example configuration (keep in mind, syntax is subject to change before the official release):

{ "enabled": true, "language_list": "HTML", "HTML 5", "XML", "PHP", "ColdFusion", "ColdFusionCFC"], "language_filter": "whitelist", "entries": {"name": "HTML/XML Tag", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"]}, {"name": "HTML/XML Tag - Block", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"], "insert_style": "block"}, {"name": "HTML/XML Tag - Block Indent", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"], "insert_style": "indent_block"} ] },

Due to swapping behavior being different than wrapping, they will have separate definitions. I am not sure if they will exist in the same settings file or have a separate swap settings file. I really am looking at swapping and wrapping as separate sub-plugins. I toyed with finding a way to make the same definition work for both, but it just got ugly. Wrapping can surround text with anything. Swapping is specifically swapping out the brackets that BH highlights.



Usage currently is select text, invoke wrapping shortcut, and use fuzzy panel to pick what you want to wrap with. So it won’t be automatic, but still pretty quick compared to how it was before.



OK, well be sure that I’m gonna check them out, even though I don’t know Python, I guess I’m gonna have to learn. :wink:

Anyway, looking forward to it. :smile:

Edit for new post: That is even more awesome! :stuck_out_tongue: