Home Download Buy Blog Forum Support

BracketHighlighter

Re: BracketHighlighter

Postby facelessuser on Sat Feb 08, 2014 10:29 pm

adamal wrote:Am I correct in assuming that this will not work with nested constructs? E.g.:

Probably will need to right a bh_plugin.

We have a proprietary language I have to use at work that is similar in this way:

for illustration
Code: Select all
def somefunction var1 var2
        if (somecondition)
            some more code;
        eif
edef


So, I define my opening and closing brackets, and then sort out which opening matches to which closing by using a bh_plugin (do until is an exception):
def compare(name, first, second, bfr):
opening = bfr[first.begin:first.end].lower()
closing = bfr[second.begin:second.end].lower()
match = False
if opening == "do":
if closing == "until":
match = True
else:
match = "e" + opening == closing
return match


Another example for handling case differences in PHP keywords:
https://github.com/facelessuser/Bracket ... eywords.py
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby facelessuser on Wed Jun 04, 2014 6:03 am

Match when cursor is on outside edge of bracket:
Okay, everyone that has been wanting this, take some time to test the new experimental feature (ST3 only currently)

Add this setting to your "bh_core.sublime-settings".

Code: Select all
"bracket_outside_adjacent": true,



There is going to be some more overhead when this is turned on, but hopefully the impact won't be too noticeable. I did this for you guys, so please do test and give feedback. If you are waiting for ST2, it may be a tomorrow or the day after.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby iamntz on Wed Jun 04, 2014 8:16 am

Few small things:

1) It seems that this command doesn't work anymore after the update (and boy, this command is damn useful!):
Code: Select all
{ "keys": ["ctrl+shift+space"], "command": "bh_key", "args": { "lines" : true, "plugin": { "type": ["__all__"], "command": "bh_modules.bracketselect" } } }

The issue is present, with without bracket_outside_adjacent set to either true or false
2) add a different scope for adjacent, so it can have different color
iamntz
 
Posts: 918
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: BracketHighlighter

Postby facelessuser on Wed Jun 04, 2014 2:02 pm

1) This is now fixed. Funny, it had nothing to do with the new algorithm...just me with a stray mutli-cursor editing something I shouldn't have.

2) How come? Current algorithm doesn't track such things. I would need to pass that info around, and it would require a bit of change to the code. Not sure I really want to spend time on that unless there was a really good reason.

FYI, I know tag outside adjacent just shows angles, I haven't updated the tag bh_plugin with support yet.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby facelessuser on Wed Jun 04, 2014 2:36 pm

Tag support for experimental outside adjacent is in.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby iamntz on Wed Jun 04, 2014 3:02 pm

Thanks! I had 3 hours of hell without that! :D

About different highlight: my idea was only in case is an easy thing to do and it aims at certain situations like this:

Image

There are some (probably) rare cases where highlight adjacent it may stay in your way. The idea is to highlight adjacent slightly different AND highlight regular brackets. So in the case i presented in the screenshots, outside brackets should be green, inside brackets should be dark (or light) green (or pink, or whatever i set in the colorscheme). Make sense?
iamntz
 
Posts: 918
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: BracketHighlighter

Postby facelessuser on Wed Jun 04, 2014 3:59 pm

iamntz wrote:Thanks! I had 3 hours of hell without that!

That just means you now appreciate me more :).

iamntz wrote:There are some (probably) rare cases where highlight adjacent it may stay in your way. The idea is to highlight adjacent slightly different AND highlight regular brackets. So in the case i presented in the screenshots, outside brackets should be green, inside brackets should be dark (or light) green (or pink, or whatever i set in the colorscheme). Make sense?


Let me think about it. I don't actually track whether I am catching an adjacent match currently. I inject some stuff to conditionally alter the algorithm to work in these adjacent cases, but it is rarely aware that the final matched brackets are in fact adjacent.

Right now, I am just happy I got it in. I have been putting it off for over a year because I just didn't want to add more complexity to an already complex system. It really wasn't as bad as I thought (once I finally spent real time analyzing what would need to be done). I know people have been wanting it though, so hopefully it works well, I figure with enough guinea pigs testing this out, we should hopefully find any overlooked problems.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby facelessuser on Wed Jun 04, 2014 5:44 pm

ST2 Experimental outside adjacent matching has been merged in.

Side note, I may add an additional option to have some bh_plugins ignore the "outside adjacent" setting. Things like pressing select and having it expand does not work with adjacent; instead, it just expands and shrinks over and over :).
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter

Postby tito on Wed Jun 04, 2014 9:35 pm

Yay! Awesome thanks a lot, much appreciated. At first insight seems to work great, and looks mixed with inside adjacent which is handy. I'll report back any oddities; I've a feature request, (that I have no idea if is complicated or not.)

When I put the cursor in
});|
It would be nice to skip the character ";" and highlight the bracket ")" this is handy for JavaScript. It would be also nice, something similar with "},|" skipping the ",". But the comma should not be skipped for example with quotes as "aasdasd",|

Thanks! :)
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 877
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: BracketHighlighter

Postby facelessuser on Thu Jun 05, 2014 12:05 am

tito wrote:Yay! Awesome thanks a lot, much appreciated. At first insight seems to work great, and looks mixed with inside adjacent which is handy. I'll report back any oddities; I've a feature request, (that I have no idea if is complicated or not.)

Please do. I am kind of relying on the community to find the issues with this...cause I'm lazy :).

tito wrote:When I put the cursor in
});|
It would be nice to skip the character ";" and highlight the bracket ")" this is handy for JavaScript. It would be also nice, something similar with "},|" skipping the ",". But the comma should not be skipped for example with quotes as "aasdasd",|

Its a cool idea, but I will be honest. When I rewrote BH1 to BH2, I did so vowing not to place language specific code in the core code. BH is surprisingly complex (and also something I need to cleanup as it has become pretty complex). The idea was always to allow the definitions to be exposed to the user and expose some kind of plugin system to do bracket manipulation if desired. I did this to take the burden off of me as I was becoming bogged down with language requests and the BH1's code base just couldn't handle it, so I threw away pyparadigm's original code started from scratch and built BH2.

What you suggest can probably be done for javascript in your user folder by excluding the current ")" in javascript and writing a rule like: open = "(\()" and close="(\)(?:;|,)?)" and then run that through a "post_match" event in a bh_plugin adjusting the selection to not include the ";" or "," if present. This is basically what tags does. Tags just does a simple match for "<" and ">" and then runs it through "post_match" event in the "tag" bh_plugin which determines it is a tag and finds the corresponding open or close matching tag. So, theoretically doable.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 8 guests