Sublime Forum

BracketHighlighter2 BETA Branch

#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

#115

Added Bracket Swapping plugin support. Also changed some things in the wrapping plugin and bracket plugin loading.

First:
If you have custom wrapping settings you need to be aware of wrapping definition changes. I made the insert_style setting an array of strings opposed to string. This allows me to consolidate redundant settings info. So now if you define only one insert style, it will automatically be applied. If the definition as more than one, it will prompt you to pick one of the styles. This way, only one bracket entry appears in the menu, and then when you select it, you will be prompted for how you wish to apply the wrapping only if there are multiple options.

Old way:

{"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"}

New way:

{"name": "HTML/XML Tag", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"], "insert_style": "inline", "block", "indent_block"]}

So if you have custom wrapping settings, change all of your insert_style settings to an array, even if you are defining only one entry.

Second:
When you update your branch, you should probably restart ST2 because I changed the modules that import the bracket plugins. It may act strange or even stop working until you restart.

Third:
Swapping should be pretty straight forward. It leverages the bracket remove and bracket wrapping plugin to apply bracket swapping. You can check out the swapping definitions in bh_swapping.sublime-settings. Swapping definitions are defined exactly like wrapping definitions, but insert_style will be ignored. Swapping does an inline bracket remove followed by an inline wrapping.

That is it. Now it is time to start doing all the documentation. All planned features are in. As always, you can report bugs etc. here or on Github.

Once I get all the documentation done, and I am certain there are no major bugs, I will be prepping for the official release.

0 Likes

#116

I’m looking for any plugin to match if / endif foreach / endforeach. Just installed BracketHighlighter from control panel but it doesn’t work.
I see many posts in this thread with promising settings like this:

{ "name": "php_keywords", "open": "^\\s*\\b(if|foreach|while)\\b(?=.*:$)", "close": "^\\s*\\b(endif\\b|endforeach\\b|endwhile(?=;$))", "icon": "dot", "color": "brackethighlighter.tag", "style": "underline", "language_filter": "whitelist", "scope_exclude": "string", "comment"], "language_list": "HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"], "plugin_library": "User.phpkeywords", "enabled": true },

…but please tell me, where I should put this settings??? I can find no info about it. Settings file BracketHighlighter.sublime-settings have another formatting style.
Cant find it here too :frowning: github.com/facelessuser/BracketHighlighter
No info in readme file

0 Likes

#117

The default install of BracketHighlighter doesn’t do the custom stuff, that branch is still in beta. Did you install the Beta BH2 branch? Or whatever Package Control installed for you (the master/default branch)?

0 Likes

#118

Where can I find beta?

0 Likes

#119

You the can see this thread here for upgrading in Package Control github.com/facelessuser/Bracket … r/tree/BH2. Package Control was having some weird upgrade issues for a bit when you define your own branch, but hopefully it is fixed now.

0 Likes

#120

Just installed BH2 from Github… but still dont know where can I configure IF/ENDIF FOR/ENDFOR matching?

0 Likes

#121

That was an old post, some things have changed since. I would try something like this in your bh_core.sublime-settings file (make a copy of it in your ST2 User folder and edit the User copy):

You can see here, I have added the PHP conditional keywords definition after the C/C++ compile switches under the setting entitled brackets.
[pre=#2D2D2D] // C/C++ compile switches
{
“name”: “c_compile_switch”,
“open”: “(\#(?:if|ifdef|ifndef))\b”,
“close”: “(\#endif)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “C++”, “C”],
“enabled”: true
},
// PHP conditional keywords
{
“name”: “php_keywords”,
“open”: “^\s*\b(if|foreach|for|while|switch)\b(?=.:$)",
“close”: "^\s
\b(endif|endfor|endforeach|endwhile|endswitch)\b(?=;$)”,
“style”: “default”,
“language_filter”: “whitelist”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.phpkeywords”,
“language_list”: “HTML”, “HTML 5”, “XML”, “PHP”, “HTML+CFML”, “ColdFusion”, “ColdFusionCFC”],
“enabled”: true
}
],[/pre]

Lastly, you create a file called phpkeywords.py in your ST2 User folder with this code:
[pre=#2D2D2D]def compare(name, first, second, bfr):
return “end” + bfrfirst.begin:first.end].lower() == bfrsecond.begin:second.end].lower()[/pre]

If I remember, I will add this by default into BracketHighlighter tonight.

0 Likes

#122

PHP Conditional Keyword highlighting is now officially on the Beta Branch.

0 Likes

#123

It not really works…

This example works:

<? foreach ($key as $val) : echo $val; endforeach; ?>

but this not:

[code]<? foreach ($key as $val) : ?>

<?=$val;?>
<? endforeach; ?> [/code]
0 Likes

#124

I’ve been trying to add some PL/SQL support, but I’m having trouble with the settings.

The settings I’m using are (based on the PHP settings):

{ "name": "plsql_keywords", "open": "^\\s*\\b(if)\\b", "close": "^\\s*\\b(end if)\\b", "style": "default", "language_filter": "whitelist", "scope_exclude": "string", "comment"], "plugin_library": "User.plsqlkeywords", "language_list": "SQL", "PL/SQL (Oracle)"], "enabled": true }

The plsqlkeywords.py file in my user directory has:

def compare(name, first, second, bfr): print name return "end " + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()

(I was trying to print the parameters so I could get a better general understanding of it’s workings)

However, BH2 is not able to call the plugin defined in the plugin_library parameter, no matter what.

In order to identify what I’m doing wrong, I’d like to clarify some things:

  • In the language_list parameter array, I should use the language name defined in the .tmLanguage file, right?
  • I’m using bizoo’s package (github.com/bizoo/Oracle), so in my case the language name should be “PL/SQL (Oracle)”. I’m assuming that there’s no need to escape the forward slash (I’ve tried renaming the language name, but without success)
  • I’ve also tried to simplify the open and close regexes to the point of just “(.)”, but even in this case the plugin is not called. Could anyone clarify me on what I could be doing wrong?

the code I’m using to test is this:

if ( true ) then null; end if;

Thanks for any help!

0 Likes

#125

[quote=“peter222”]It not really works…

This example works:

<? foreach ($key as $val) : echo $val; endforeach; ?>

but this not:

[code]<? foreach ($key as $val) : ?>

<?=$val;?>
<? endforeach; ?> [/code][/quote]

Well, it works, but you don’t quite understand the rules. PHP has some quirks.

This is simply a case of dangling brackets. You can see here that the curly braces are not actually matches.

({)(})

The algorithm is very general in BracketHighlighter so that it works with all languages. Stuff like this is a bit tricky to deal with without making some concessions.

So, I have updated the PHP Conditional Keywords on the Beta branch, but in order for this to work for you, you have to ignore <?**, **<?php**, and **?>. If you do this, those will no longer be highlighted, but BracketHighlighter will be able to see things like the foreach and endforeach across the <? ?> punctuation.

So update your BH2 branch and then change your Angle definition to match this in your User/bh_core.sublime-settings file.

// Angle { "name": "angle", "open": "(<)", "close": "(>)", "style": "angle", "scope_exclude": "string", "comment", "keyword.operator", "punctuation.section.embedded.end.php", "punctuation.section.embedded.begin.php"], "language_filter": "whitelist", "language_list": "HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"], "plugin_library": "bh_modules.tags", "enabled": true },

That is the best I can do for you.

Edit: I am sure other things can break this like comments right before or right after the php punctuation, but if someone wants to take the time to code up the “perfect” regex, I will pull it in, but this should work in most cases; not sure if there will be any side effects when ignoring <? and ?>. This isn’t guaranteed to be perfect, I kind of expect the community to polish up the regex for their languages and save me from trying to come up with the regex for every language that I might not even use.

0 Likes

#126

[quote=“rogenaro”]I’ve been trying to add some PL/SQL support, but I’m having trouble with the settings.

The settings I’m using are (based on the PHP settings):

{ "name": "plsql_keywords", "open": "^\\s*\\b(if)\\b", "close": "^\\s*\\b(end if)\\b", "style": "default", "language_filter": "whitelist", "scope_exclude": "string", "comment"], "plugin_library": "User.plsqlkeywords", "language_list": "SQL", "PL/SQL (Oracle)"], "enabled": true }

The plsqlkeywords.py file in my user directory has:

def compare(name, first, second, bfr): print name return "end " + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()

(I was trying to print the parameters so I could get a better general understanding of it’s workings)

However, BH2 is not able to call the plugin defined in the plugin_library parameter, no matter what.

In order to identify what I’m doing wrong, I’d like to clarify some things:

  • In the language_list parameter array, I should use the language name defined in the .tmLanguage file, right?
  • I’m using bizoo’s package (github.com/bizoo/Oracle), so in my case the language name should be “PL/SQL (Oracle)”. I’m assuming that there’s no need to escape the forward slash (I’ve tried renaming the language name, but without success)
  • I’ve also tried to simplify the open and close regexes to the point of just “(.)”, but even in this case the plugin is not called. Could anyone clarify me on what I could be doing wrong?

the code I’m using to test is this:

if ( true ) then null; end if;

Thanks for any help![/quote]

I will take a look when I have some time.

0 Likes

#127

@rogenaro you weren’t far off at all. The problem was simply that the language name you see in the bottom right hand corner of the window is not always the name you use. You actually use the name of the tmLanguage file, which in your case is PL_SQL (Oracle).tmLanguage so the final definition would look like this:

[pre=#2D2D2D] // Oracle conditional keywords
{
“name”: “plsql_keywords”,
“open”: “^\s*\b(if)\b”,
“close”: “^\s*\b(end if)\b”,
“style”: “default”,
“language_filter”: “whitelist”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.plsqlkeywords”,
“language_list”: “SQL”, “PL_SQL (Oracle)”],
“enabled”: true
}[/pre]

The ST2 always returns the name of the language internally as the name of the tmLanguage file, not the friendly name you see in the bottom right hand corner of your window; sometimes these match up, but in your case they do not.

0 Likes