Sublime Forum

BracketHighlighter

#129

@Voaxeyr The readme explains all of this here: github.com/facelessuser/Bracket … ight-style

But to directly answer your question, you can copy the bh_core.sublime-settings file to your Packages/User folder and change the default to solid like shown below:

[pre=#252525] “default”: {
“icon”: “dot”,
“color”: “brackethighlighter.default”,
“style”: “solid”
},[/pre]

If you want to change a specific bracket to be this way, and others to be different, you can can tweak them on an individually; all of this is covered in the readme.

0 Likes

#130

Is there any website with style examples ? I see there’s a lot nice color schemes, no need to make it from scratch.

0 Likes

#131

@ceroz, I am not entirely sure what you mean; can you elaborate?

0 Likes

#132

I like your bh style:

I am looking for something similar but exactly the same characters on margin:
()
|
|
|
()

I would like to get some ready to use codes for styling my BH plugin :wink:

0 Likes

#133

I’m right thinking that is not possible to install correctly the package with package control 2?
I had have to git clone and then switch to bh2st3

0 Likes

#134

[quote=“ceroz”]

I like your bh style:

I am looking for something similar but exactly the same characters on margin:
()
|
|
|
()

I would like to get some ready to use codes for styling my BH plugin :wink:[/quote]

It was a proof of concept, but it isn’t a practical style. I think I outline a number of the issues with it in the same post.

[quote=“tito”]I’m right thinking that is not possible to install correctly the package with package control 2?
I had have to git clone and then switch to bh2st3[/quote]

Works fine with Package Control 2. It is all setup in PC 2 to download the appropriate branch. The thing is, you must delete the unpacked version from your Packages folder, or it will override your Installed Packages version (the archived sublime-package version).

0 Likes

#135

It turns out there was some hard-coded setting in my Package Control.sublime-settings file that prevented this package from being installed correctly.
After cleaning /User/PAckageControl.sublime-settings most of the setttings, the package install correctly. Thanks ! and sorry for the false alarm. :blush: :stuck_out_tongue:

0 Likes

#136

[quote=“tito”]It turns out there was some hard-coded setting in my Package Control.sublime-settings file that prevented this package from being installed correctly.
After cleaning /User/PAckageControl.sublime-settings most of the setttings, the package install correctly. Thanks ! and sorry for the false alarm. :blush: :stuck_out_tongue:[/quote]

No worries, I had the same thing happen to me with a couple of plugins.

0 Likes

#137

I’m curious if anyone figured out a way to change the solid style highlight border. Currently, mine is this nasty lime green color; which doesnt match anything in my theme.

Also, why do I lose all coloring with the solid style highlight? Variables, operators, basically everything just turns to monochrome for everything within the brackets.

BTW: Thanks for the great plugin!

[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]

0 Likes

#138

The borders of solid highlights are not accessible via the API, so there isn’t really a way to customize it. I think you can turn off the border (if I remember correctly), but then the selections just look blocky.

0 Likes

#139

Thanks for the reply. I really appreciate it! One more question…
Is there a way to specify minimum number of lines (or characters) threshold?

I dont want it to highlight brackets that are too close together. Its kind of distracting, and not necessary since it’s obvious where they are already. I just want it to highlight brackets that are further apart, if possible.

0 Likes

#140

Not currently. If I can get it in without mucking up anything else, I wouldn’t mind doing it. Please create a github issue at the repo.

0 Likes

#141

Done! Thanks.

0 Likes

#142

I noticed that Sublime Text locks up for a few seconds when I first open it with a a script file. I’m guessing it’s pretty resource intensive when bracket highlighter first initializes. Is there any way to somehow preemptively cache bracket highlighter so it doesn’t lockup ST3 every time when I close and restart ST3? Maybe, there are some performance tips/settings I could use to alleviate this symptom?

BTW: Add me to the list of people who think this plugin is a MUST HAVE for Sublime Text.

0 Likes

#143

This is what BracketHighlighter does:

  • On startup: start a thread to watch for view changes or selection changes and intialize the matcher object
  • On view focus: determine which rules etc. it needs to load up for the focused files
  • On selection: match and optionally run bracket plugin modules as requested

There is one thing that takes a second or two, and that is creating a unicode table for unicode property support in regex rules (like this r"\p{Ll}\p{Lu}]"). But it happens only once, and I now defer it until the first call to use it, then it shouldn’t happen again unless the plugin gets reloaded. Deferring this allows ST Gui to load up without any lag.

ST Startup will probably do all these things:

  • Startup: causing the BH plugin to load (pretty quick)
  • Load views and focus one causing BH to load up rules (also negligible; try switching tabs, this causes BH to this)
  • Places cursor in view which causes BH to do its first match causing the initial unicode table to load and then perform the match (this will cause the unicode property table to initialize)

Hardcoding the unicode table can probably help in the first view load time, or maybe caching that. I am sure this could probably just be loaded once, and then pickled for later use…

The plugin is surprisingly complicated to allow for all the different tweakable stuff and to be general enough to allow people to add their custom brackets via the settings files and/or specialized functions via bracket plugins. In general though, I don’t notice performance slow down because of the plugin. Probably the unicode table loading is the one thing that takes a couple of seconds.

If I get some time, I may look into caching the unicode property list. I also take pull requests :smile:.

0 Likes

#144

Thanks for taking a look at it. It certainly would be nice to be able to avoid the initial “lockup”. Im guessing it’s bit more of an issue for people like me who make small scripts (frequently exiting/starting Sublime Text). If I knew python, I would definitely attempt to fix it myself.

0 Likes

#145

@MKANET, please create an issue on Github, and I will try and get to it soon; this is a pretty straight forward task.

0 Likes

#146

Hi,

is it possible to call a function from bracket highlighter from another ST plugin to find the position of the current opening (? So if this is the code

read.dta('filepath',|

and the curser us at |, I would like to get the position of the ( bracket. I know that I can program that with the ST API but I was wondering whether I can call a BracketHighlighter function to get that position?

Thanks for the great plugin!

0 Likes

#147

Yes you can. Or I should say you can send them from BH. I don’t currently have a command to call that just finds the brackets and returns the info without highlighting. If you plan on modifying the bracket, you might consider doing it all in a bh_plugin. But you at least need to call bh_plugin to send the info out:

So lets pretend I have a SublimePlugin called NotifyBrackets. It is going to select the actual brackets and notify the user the location of the brackets.

Directory structure (bh_plugins really shouldn’t be in a top level folder; they are going to dynamically be loaded when needed. So I put them in bh_modules with no init.py file)

- Packages
    - NotifyBrackets
        - bh_modules
            notifybracket.py
        Default.sublime-commands

Simple Code will format a message with the bracket locations and send the info to my SubNotify command to popup a notification bubble. It will also log it in the Sublime console. At the end, I modify the selections so BH will select the brackets when it is done processing all my brackets.

notifybracket.py
[pre=#232628]import BracketHighlighter.bh_plugin as bh_plugin
import sublime

class NotifyBracket(bh_plugin.BracketPluginCommand):
def run(self, edit, name):
text = “Bracket Type: %s\n” % name
text += “Left bracket range (%(begin)d, %(end)d)\n” % {“begin”: self.left.begin, “end”: self.left.end}
text += “Right bracket range (%(begin)d, %(end)d)” % {“begin”: self.right.begin, “end”: self.right.end}
sublime.run_command(“sub_notify”, {“title”: “NotifyBracket”, “msg”: text})
print(text)
self.selection = sublime.Region(self.left.begin, self.left.end), sublime.Region(self.right.begin, self.right.end)]

def plugin():
return NotifyBracket[/pre]

In my command file, I setup the calling of the command:
Default.sublime-commands
[pre=#232628]
// Highlight and notify about bracket
{
“caption”: “NotifyBracket: Highlight and Notify Brackets”,
“command”: “bh_key”,
“args”:
{
“plugin”:
{
“type”: “all”],
“command”: “NotifyBracket.bh_modules.notifybracket”
}
}
}
][/pre]

Output

Bracket Type: round Left bracket range (85, 86) Right bracket range (116, 117)

I believe most things for the bh_plugin API are documented…maybe not well, but they should be documented. If you find something missing, let me know. There are some complications you might run into if doing extremely complex modifications to a view while processing the brackets. I have a bug that causing bracket swapping not to work when you have multiple brackets targeted that are nested inside of each other. But most other things should work. That is just a limitation in the current iteration of bh_plugins that we have to live with right now.

Maybe in the future I will add a command to just return bracket positions. We shall see.

Hope that helps and didn’t overwhelm you :smile:.

0 Likes

#148

If you just really want a command that returns bracket positions without using a bh_plugin, feel free to create an issue. It might not be that hard to do…I would just need to find the time.

0 Likes