Sublime Forum

BracketHighlighter

#175

New Feature to help with defining custom rules added (ST3 ONLY).

One of the slightly annoying things about BH is that if you want to try out a custom rule, or modify an existing one, you need to copy the whole default set of rules. If you do this in your User folder, new updates to BH rules will not be picked up until you rebase your rules.

Well, I set out to fix that with some new changes I will outline below:

Let’s say you have a custom language you want to have on your machine. Now, you can simply add it to one of the two settings arrays: “user_scope_brackets” and “user_brackets”:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”:
{
“name”: “mylang”,
“open”: “^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\b”,
“close”: “\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.bh_modules.mylangkeywords”,
“language_filter”: “whitelist”,
“language_list”: “mylang”],
“enabled”: true
}
],[/pre]

Let’s say you want to modify an existing rule, maybe just tweak the language list, all you have to do is use the same name and the item you want to change. Only that attribute will be overridden:
[pre=#232628] “user_brackets”:
// Angle
{
“name”: “angle”,
“language_list”:
“HTML”, “HTML 5”, “XML”, “PHP”, “HTML (Rails)”,
“HTML (Jinja Templates)”, “HTML (Twig)”, “HTML+CFML”,
“ColdFusion”, “ColdFusionCFC”, “laravel-blade”,
“Handlebars”, “AngularJS”,
“SomeNewLanguage” // <— New language
]
}
],[/pre]

Let’s say I want to insert a new rule between two rules. I can turn on debug mode and call the BracketHighlighter: (Debug) Filter Rules by Key then select position to see the current rule order and their postion index:

[pre=#232628]

    {"name": "curly", "position": 0},
    {"name": "round", "position": 1},
    {"name": "square", "position": 2},
    {"name": "html", "position": 3},
    {"name": "cfml", "position": 4},
    {"name": "php_angle", "position": 5},
    {"name": "angle", "position": 6},
    {"name": "cssedit_groups", "position": 7},
    {"name": "ruby_embedded_html", "position": 8},
    {"name": "ruby", "position": 9},
    {"name": "c_compile_switch", "position": 10},
    {"name": "php_keywords", "position": 11},
    {"name": "erlang", "position": 12},
    {"name": "bash", "position": 13},
    {"name": "fish", "position": 14},
    {"name": "mylang", "position": 15}
],

    {"name": "py_single_quote", "position": 0},
    {"name": "py_double_quote", "position": 1},
    {"name": "single_quote", "position": 2},
    {"name": "double_quote", "position": 3},
    {"name": "jsregex", "position": 4},
    {"name": "perlregex", "position": 5},
    {"name": "rubyregex", "position": 6},
    {"name": "mditalic", "position": 7},
    {"name": "mdbold", "position": 8}
]

][/pre]

Then you can specify the position you want to insert at:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”:
{
“name”: “mylang”,
“position”: 4, // <-- New position
“open”: “^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\b”,
“close”: “\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.bh_modules.mylangkeywords”,
“language_filter”: “whitelist”,
“language_list”: “mylang”],
“enabled”: true
}
],[/pre]

And if you run the debug command again, you will see that the position has changed:

[pre=#232628] {“name”: “curly”, “position”: 0},
{“name”: “round”, “position”: 1},
{“name”: “square”, “position”: 2},
{“name”: “html”, “position”: 3},
{“name”: “trex”, “position”: 4}, // <-- New position
{“name”: “cfml”, “position”: 5},
{“name”: “php_angle”, “position”: 6},[/pre]

This can be used to adjust the position of default rules from your user settings as well as shown by overrides above.

So, unless you are forking BH to pull request a change to the default rules, you can now modify the rules all in these two settings without copying or touching the default rules:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”: ],[/pre]

This will allow you to make changes, but still receive new updated rules.

**Debug mode is a setting in the settings file. Toggling debug mode via command palette only changes the settings in memory, so when you save the settings file, it reverts back to the original. I choose not to save it automatically to the settings file so as not to regenerate the settings file and erase all the comments in the settings file. If you want to put the plugin in a more “hard” debug mode, set “debug” to “true” manually in your settings file.

0 Likes

#176

Hello!

Sorry if this is the wrong place to ask for this.

I love this plugin, but I lack, err, the artistic eye (reason I don’t do website design) so am having a hard time making visually appealing colour choices
and highlighting styles for myself. If anyone could share their relevant settings for a dark backgrounds I’d appreciate it. :smile:

Sorry for the inconvenience. :blush:

0 Likes

#177

A couple of new additions (ST3 Only):

Content Bar
This is an experimental content bar. This is a feature that has been requested a number of times, but I have held off due to Sublime’s limitations. I have added recently only as an experiment, but I may keep it around. This is experimental and not guaranteed to stick around and its features/behavior are subject to change. The future of this feature depends on the feedback I get, so please do give feedback: negative or positive.

So This experimental feature exists in two forms. The first can be seen by enabling the new “content_highlight_bar” setting. This will draw a line highlighting a brackets content at the start of the line. This has the lowest overhead and works with monospace fonts and proportional fonts.

So the second form has a bit more overhead and probably only works well on monospace fonts. This form draws the content bar at the brackets indentation level. It can not draw the line across empty spaces, and I currently do not draw the line if text comes before the line (this is illustrated in the first example below). Feature requires “content_highight_bar” and “align_content_highlight_bar” to be set to true.

Toggle Brackets
This feature is made possible by some changes made to the “bracketselect” bh_plugin. By setting up the selection key binding as shown below, instead of jumping through nested brackets in just one direction, this binding will toggle between the opening and closing of the current bracket only:

[pre=#232628] {
“keys”: “ctrl+m”],
“command”: “bh_key”,
“args”:
{
“no_outside_adj”: true,
“lines” : true,
“plugin”:
{
“type”: “all”],
“command”: “bh_modules.bracketselect”,
“args”: {“select”: “right”, “alternate”: true}
}
}
},[/pre]

Anyways hope you enjoy, and please leave feedback about the experimental content bar feature.

0 Likes

#178

Hi, Im just wondering if the brackets(open n close) is not highlighted does that mean that there is something wrong with the codes in the brackets? because i have something like this:

if()
{
  if()
  {
     
  }
  else
  {

  }
}

the second ifs curly brackets and else are highlighted but the first ifs curly bracket doesnt get highlighted.

0 Likes

#179

You need to be a bit more specific on your scenario. Where are your cursors? BH highlights the immediate brackets enclosing the cursor. It does not show all nested brackets, just eh immediate brackets around the cursor.

0 Likes

#180

Great package, has been a real time saver for me.

I have a question though. I cannot get curly bracket icon to show in same color as bracket highlight; it just shows in black which is really hard to see. You have to look really closely to see at all.

Tried everything; can you suggest how I can change this please?

Screenshot:

When setting the color options what are the difference between the foreground and background please?

0 Likes

#181

@kmm2908, please post your settings rule and your color-scheme configured rule that goes along with it so I can understand what you are doing.

0 Likes

#182

[quote=“facelessuser”]A couple of new additions (ST3 Only):

Content Bar … [/quote]

Many thanks, facelessuser.
This is definately a useful feature!

0 Likes

#183

[quote=“jfcherng”]Many thanks, facelessuser.
This is definately a useful feature![/quote]

Your welcome :wink:.

0 Likes

#184

The custom color is working on the bracket highlight, it is just the icon in the gutter that is black and hard to see.

Settings:

“curly”: {
“icon”: “curly_bracket”,
“color”: “brackethighlighter.curly”,
“style”: “outline”
},
“round”: {
“icon”: “round_bracket”,
“color”: “brackethighlighter.round”
// “style”: “underline”
},
“square”: {
“icon”: “square_bracket”,
“color”: “brackethighlighter.square”
// “style”: “underline”
},
“angle”: {
“icon”: “angle_bracket”,
“color”: “brackethighlighter.angle”
// “style”: “underline”
},
“tag”: {
“icon”: “tag”,
// “endpoints”: true,
“color”: “brackethighlighter.tag”,
“style”: “outline”
},
“c_define”: {
“icon”: “hash”
// “color”: “brackethighlighter.c_define”,
// “style”: “underline”
},
“single_quote”: {
“icon”: “single_quote”,
“color”: “brackethighlighter.quote”
// “style”: “underline”
},
“double_quote”: {
“icon”: “double_quote”,
“color”: “brackethighlighter.quote”
// “style”: “underline”
},
“regex”: {
“icon”: “regex”,
“color”: “brackethighlighter.quote”
// “style”: “underline”
}

Color entries in theme file:

// custom colors for brackethighlighter.

name
Bracket quote
scope
brackethighlighter.quote
settings

background
#F00
foreground
#FFF



name
Bracket curly
scope
brackethighlighter.curly
settings

background
#0F0
foreground
#FFF



name
Bracket round
scope
brackethighlighter.round
settings

background
#00F
foreground
#FFF



name
Bracket square
scope
brackethighlighter.square
settings

background
#FF0
foreground
#FFF



name
Bracket angle
scope
brackethighlighter.angle
settings

background
#0FF
foreground
#FFF



name
Bracket tag
scope
brackethighlighter.tag
settings

background
#FFF

Let me know if I need to post anything else.

Thanks for quick reply.

0 Likes

#185

@kmm2908, only set the foreground color.

Sublime takes the foreground color and tints the icon. Background color should do nothing.

0 Likes

#186

[quote=“facelessuser”]@kmm2908, only set the foreground color.

Sublime takes the foreground color and tints the icon. Background color should do nothing.[/quote]

Yep that fixed it thanks!

0 Likes

#187

Hi everybody,

I am trying to modify the highlight of html tags. I would like the common tag be highlighted like that

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras congue quis augue eget blandit.

instead of

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras congue quis augue eget blandit.

I tried to change the “open” and “close” attributes of “angle” style (with copying pasting code below in “user_brackets” behavior), or change “scope_exclude” parameters, no to avail !

"user_brackets": { "name": "angle", "open": "(<)(?=^?%]|$)", "close": "(?:(?<=^?%])|(?<=^))(>)", "style": "angle", "scope_exclude": "string", "comment", "keyword.operator", "source.ruby.rails.embedded.html", "source.ruby.embedded.html"], "language_filter": "whitelist", "language_list": "HTML", "HTML 5", "XML", "PHP", "HTML (Rails)", "HTML (Jinja Templates)", "HTML (Twig)", "HTML+CFML", "ColdFusion", "ColdFusionCFC", "laravel-blade", "Handlebars", "AngularJS"], "plugin_library": "bh_modules.tags", "enabled": true } ],

Someone could help me please ?

Thanks in advance

0 Likes

#188

You can try setting endopoints to your tag style under bracket_styles:

[pre=#232628] “tag”: {
“icon”: “tag”,
“color”: “brackethighlighter.tag”,
“style”: “outline”,
“endpoints”: true
},[/pre]

This will only highlight the angled brackets of an opening and closing tag. This is a little more low profile, but currently, an option to highlight just the tag name does not exist. I don’t hard code highlights for specific rules as the core code is generic. Maybe in the future I will add a hook to allow a bh_plugin to modify the highlight region separately from the tag region.

0 Likes

#189

I am trying to reproduce the notepad++ behaviour for a upcoming theme, so your trick doesn’t help me unfortunately.
Thank you for the speed and clarity of your reply !

0 Likes

#190

I realize it’s not the same; so, if it’s “that” or nothing, then yes, you are out of luck unless I get motivated sometime soon to add such a feature.

0 Likes

#191

FYI, a critical bug that was introduced with the latest Sublime build 3067, has been patched in the latest BH. Please update to avoid having Sublime freeze up.

Also, I added a new hook that now allows for tag brackets to only highlight the tag name. There has been a number of requests for this in the past.

0 Likes

#192

So it was something wrong! Dev Build 3067

0 Likes

#193

I don’t know if the crashes were related, but Jon changed how EOF was handled in match_selectors which caused BH to go into an infinite loop when processing scope rules at the end of a file.

0 Likes

#194

FYI for BH users. A new public beta for Sublime should be coming out soon. Some recent changes had been made to Sublime on the dev releases that were incompatible with BH causing freezing or crashing. BH has since been patched, but Jon wanted to minimize bug reports when the new beta is released, so he contacted me and we worked out a way for him to exclude older BH versions that don’t have the fix.

Basically, in the 2.4.0 release I did this morning, I added a dummy file that can be checked by Sublime. When the new beta drops, all BH releases before the 2.4.0 release will not work on 3070+ builds of Sublime. My advice is to upgrade now.

Edit: Go with 2.4.1 instead. I was dumb and broke HTML tags in PHP syntax; 2.4.1 fixes that. Oh well.

0 Likes