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 .