Sublime Forum

BracketHighlighter

#1

Bracket Highlighter is a fork of pyparadigm’s SublimeBrackets and SubimeTagmatcher merged together. I never intended this fork to be anything more than me fixing a couple of things, but then it took on a life of its own.

There are a number improvements to the functionality of the originals and new features:

  • Customizable debounce and search thresholds to ensure the plugin doesn’t get bogged down in big files

  • Matches tags; brackets: (), ], <>, {}; and quotes: single and double (uses string scope)

  • Ability to blacklist or whitelist languages from matching specific brackets, tags, quotes

  • Ability to turn off matching compeletly off for any bracket, quote, or tag

  • On demand shortcut to override search threshold and search until the match is made no matter how far it must search

  • Highlight styles: colored blocks, colored outline, or colored underline

  • Highlight entire Tag or just the brackets of a tag

  • Show line count and character count between blocks when using on demand shortcut

  • Settings are tweakable in the settings file

  • Settings file and keymap files are accessible from the menu

  • Bracket plugins: (this might sound silly to have plugins inside a plugin, but it is actually useful)

Plugins:
BracketHighlighter does the work of finding matching brackets, tags, and quotes. Bracket plugins allows you to leverage this work to find the regions without having to duplicate the logic in other plugins. Plugins can be dropped into the BracketHighlighter folder, or dropped in their own plugin folder (I may separate plugins into their own repo in the future).

Current plugins:

  • Swap quote type of string
    : changes from single quoted to double quoted or vice versa. Accounts for escaped quotes
  • Bracket select
    : Change the selection inside the bracket, tag, or quote block. Move the cursor to first bracket of match or last and focus. Select entire content between matched brackets, quotes, or tags
  • Tag name select
    : select the tag name of the opening and closing HTML tag to edit the names at the same time
  • Tag attribute select
    : cycle through selecting the attributes of an HTML tag
  • Fold brackets
    : Fold code by brackets
  • Swap brackets
    : Change current matched brackets to specified bracket type

All of these default plugins come bound to shortcuts (there are so many shortcuts in ST2 that I did the best I could, if you don’t like the shortcuts, feel free to change them and bind them to ones that make sense for you. If you don’t like some of the plugins, you can toss them and remove the shortcut.).

The repo is here: BracketHighlighter

Feel free to let me know what you think; good or bad. Make suggestions or anything else.

2 Likes

"Unwrap" selection
#2

+rep!

Thanks :smile:

0 Likes

#3

Great stuff! Don’t forget to submit your repo to Package Control (will@wbond.net) so it can be installed that way.

0 Likes

#4

You can manually add the repo URL through Package Control so it’s not really an issue, though it would be nice to have the exposure through the official channel.

0 Likes

#5

Yeah, it is on my list of things to do. Getting pretty busy at work right now, but I hope to get it going by the end of this week or next.

0 Likes

#6

BracketHighlighter is now on Package Control, but you cannot install because the repo for some reason is now flaking out on “download repo as zip”. Not sure what is going on because I used the feature earlier today. I am trying to figure out what is going on. Hopefully github has reasonable support, or maybe it is something that will resolve itself with a little time.

0 Likes

#7

Should now be work on package control. Not sure what the issue was, but it works now.

0 Likes

#8

Having trouble with the plugin at the moment. It seems to not be able to read the settings correctly. True on both Mac and Linux. Couldn’t figure it out offhand.

0 Likes

#9

Have you restarted after installing? It seems a good restart after first install is usually what it needs. After that you can tweak the settings and they will immediately take place. I personally use it on Windows and Linux, so I have tested it works on both.

Let me know if you are still having issues after a restart.

I have actually seen similar behavior before with other plugins…usually ones that have multiple files. I think it has to do with the fact that as each file is added during install to the ST2 path, if the other dependency has not yet been copied, that file errors out, and after the dependency is copied, the original file that failed does not reload; therefore, after install, you need to restart so that all files will be reloaded with all in place.

0 Likes

#10

Yea, seems like a restart on the Mac seemed to do the trick. Will have to try the Linux version later. Will report back.

0 Likes

#11

Nice work, loving this plugin! Is there any way to modify the color?

0 Likes

#12

Yeah, you can open up the setting file and change the color. The color is based on the scope you assign to the highlight. By default it is “entity.name.class”, but you could change it to “keyword” or any other scope in your theme.

//Scope? (Defined in theme files.) -> //Examples: (keyword/string/number) "quote_scope" : "entity.name.class", "curly_scope" : "entity.name.class", "round_scope" : "entity.name.class", "square_scope": "entity.name.class", "angle_scope" : "entity.name.class", "tag_scope" : "entity.name.class",

If you want more control of the color, you can add your own scope to your current theme file and tweak to any color you would like.

<dict> <key>name</key> <string>Bracket Tag</string> <key>scope</key> <string>bracket.tag</string> <key>settings</key> <dict> <key>foreground</key> <string>#FD971F</string> </dict> </dict> <dict> <key>name</key> <string>Bracket Curly</string> <key>scope</key> <string>bracket.curly</string> <key>settings</key> <dict> <key>foreground</key> <string>#66D9EF</string> </dict> </dict> <dict> <key>name</key> <string>Bracket Round</string> <key>scope</key> <string>bracket.round</string> <key>settings</key> <dict> <key>foreground</key> <string>#F92672</string> </dict> </dict> <dict> <key>name</key> <string>Bracket Square</string> <key>scope</key> <string>bracket.square</string> <key>settings</key> <dict> <key>foreground</key> <string>#A6E22E</string> </dict> </dict> <dict> <key>name</key> <string>Bracket Angle</string> <key>scope</key> <string>bracket.angle</string> <key>settings</key> <dict> <key>foreground</key> <string>#AE81FF</string> </dict> </dict> <dict> <key>name</key> <string>Bracket Quote</string> <key>scope</key> <string>bracket.quote</string> <key>settings</key> <dict> <key>foreground</key> <string>#FAF60A</string> </dict> </dict>

This would allow you to do this:

//Scope? (Defined in theme files.) -> //Examples: (keyword/string/number) "quote_scope" : "bracket.quote", "curly_scope" : "bracket.curly", "round_scope" : "bracket.round", "square_scope": "bracket.square", "angle_scope" : "bracket.angle", "tag_scope" : "bracket.tag",

0 Likes

#13

Thanks!

0 Likes

#14

Added Fold by Brackets, and** Swap Brackets** plugin to Bracket Highlighter.

Fold by Brackets:
Fold code block by brackets opposed to ST2’s indention method. I will include this until ST2 supports fold by brackets natively.

Swap Brackets:
Use shortcut, or command to bring up a quick panel to select a bracket type to change current matched bracket(s) to. Works with multi-select.

0 Likes

#15

Just installed this package yesterday and I love it. Helps bring a bit more color while providing a functional use.

A minor annoyance is how using the ‘solid’ outline style makes it a bit difficult to see the cursor, especially with the default bright-yellow quote-bracket color. Switching to the “outline” style mostly relieves the issue, though.

That said, great product, many thanks!

-TA

0 Likes

#16

The plugin is very configurable; I personally use underline with a bold color that stands out. The default color is based on the colors in your theme, but you can get better control of the colors; just check out the readme of the plugin, and it will tell you how to change colors, etc.

Glad you like it.

0 Likes

#17

Hi, thank you for your nice package! One question - is there a way to change color for highlight border? with option “underline” and “outline” color applies to border and it’s fine but type “solid” doesn’t give a way to define border color

grab.by/bVsO

0 Likes

#18

[quote=“rooc”]Hi, thank you for your nice package! One question - is there a way to change color for highlight border? with option “underline” and “outline” color applies to border and it’s fine but type “solid” doesn’t give a way to define border color

grab.by/bVsO[/quote]

Unfortunately no. The api doesn’t even allow me to directly set the color of the region; I instead specify a scope, and that scope must be defined in the color scheme file. This is the description from the Sublime Text 2 API (this is the command I use to create the colored regions).

[code]add_regions(key, [regions], scope, , ) None

Add a set of regions to the view. If a set of regions already exists with the given key, they will be overwritten. The scope is used to source a color to draw the regions in, it should be the name of a scope, such as “comment” or “string”. If the scope is empty, the regions won’t be drawn.
The optional icon name, if given, will draw the named icons in the gutter next to each region. The icon will be tinted using the color associated with the scope. Valid icon names are dot, circle, bookmark and cross.

The optional flags parameter is a bitwise combination of:

sublime.DRAW_EMPTY. Draw empty regions with a vertical bar. By default, they aren’t drawn at all.
sublime.HIDE_ON_MINIMAP. Don’t show the regions on the minimap.
sublime.DRAW_EMPTY_AS_OVERWRITE. Draw empty regions with a horizontal bar instead of a vertical one.
sublime.DRAW_OUTLINED. Draw regions as an outline, rather than filled in.
sublime.PERSISTENT. Save the regions in the session.
sublime.HIDDEN. Don’t draw the regions.[/code]

0 Likes

#19

hi faceless XD
i want to change the icon to mark the line in whic we have the bracket…where do u take the icons?

0 Likes

#20

[quote=“Fed03”]hi faceless XD
i want to change the icon to mark the line in whic we have the bracket…where do u take the icons?[/quote]

I add the icons via the API discussed a couple of posts up. This is from the description of the API method “add_regions”:

The optional icon name, if given, will draw the named icons in the gutter next to each region. The icon will be tinted using the color associated with the scope. Valid icon names are dot, circle, bookmark and cross.

You will notice though the cross never gets tinted, this is a problem with the API. You can maybe hunt down the icon in the theme and change it; that might work. I don’t think you add new ones because I think the API only look for those specific 4.

0 Likes