The problem is that BH has recently begun to rely on dependencies (because they make my life easier). It relies on Package Control to ensure those dependencies are found in the path before the plugin requests them. You can install the dependencies and BH, but you must ensure the dependencies are found in the path before BH gets loaded. You could do this with a plugin that loads the dependencies (this is basically what package control does - it creates a plugin that gets loaded before other plugins that then loads the all the dependencies into the path).
ST3: BracketHighlighter 2
Here is a write up of how to install BH without Package Control:
Download the latest releases of the following dependencies and unpack in the Packages
folder as shown below:
- https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-markupsafe -> markupsafe
- https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-jinja2 -> python-jinja2
- https://github.com/packagecontrol/pygments -> pygments
- https://github.com/facelessuser/sublime-markdown-popups -> mdpopups
- https://github.com/facelessuser/sublime-markdown -> python-markdown
- https://github.com/facelessuser/sublime-backrefs -> backrefs
Get the latest BracketHighlighter release and unpack as BracketHighlighter
:
- https://github.com/facelessuser/BracketHighlighter -> BracketHighlighter
Create a folder under Packages
called 00-dependencies
and under that folder create a file called 00-dependencies.py
:
Copy the following code to 00-dependencies.py
(this code was taken from Package Control):
import sys
import os
from os.path import dirname
if os.name == 'nt':
from ctypes import windll, create_unicode_buffer
import sublime
if sys.version_info >= (3,):
def decode(path):
return path
def encode(path):
return path
if os.path.basename(__file__) == 'sys_path.py':
pc_package_path = dirname(dirname(__file__))
# When loaded as a .sublime-package file, the filename ends up being
# Package Control.sublime-package/Package Control.package_control.sys_path
else:
pc_package_path = dirname(__file__)
st_version = u'3'
else:
def decode(path):
if not isinstance(path, unicode):
path = path.decode(sys.getfilesystemencoding())
return path
def encode(path):
if isinstance(path, unicode):
path = path.encode(sys.getfilesystemencoding())
return path
pc_package_path = decode(os.getcwd())
st_version = u'2'
st_dir = dirname(dirname(pc_package_path))
def add(path, first=False):
"""
Adds an entry to the beginning of sys.path, working around the fact that
Python 2.6 can't import from non-ASCII paths on Windows.
:param path:
A unicode string of a folder, zip file or sublime-package file to
add to the path
:param first:
If the path should be added at the beginning
"""
if os.name == 'nt':
# Work around unicode path import issue on Windows with Python 2.6
buf = create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(path, buf, len(buf)):
path = buf.value
enc_path = encode(path)
if os.path.exists(enc_path):
if first:
try:
sys.path.remove(enc_path)
except (ValueError):
pass
sys.path.insert(0, enc_path)
elif enc_path not in sys.path:
sys.path.append(enc_path)
def remove(path):
"""
Removes a path from sys.path if it is present
:param path:
A unicode string of a folder, zip file or sublime-package file
"""
try:
sys.path.remove(encode(path))
except (ValueError):
pass
if os.name == 'nt':
buf = create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(path, buf, len(buf)):
path = buf.value
try:
sys.path.remove(encode(path))
except (ValueError):
pass
def generate_dependency_paths(name):
"""
Accepts a dependency name and generates a dict containing the three standard
import paths that are valid for the current machine.
:param name:
A unicode string name of the dependency
:return:
A dict with the following keys:
- 'ver'
- 'plat'
- 'arch'
"""
packages_dir = os.path.join(st_dir, u'Packages')
dependency_dir = os.path.join(packages_dir, name)
ver = u'st%s' % st_version
plat = sublime.platform()
arch = sublime.arch()
return {
'all': os.path.join(dependency_dir, 'all'),
'ver': os.path.join(dependency_dir, ver),
'plat': os.path.join(dependency_dir, u'%s_%s' % (ver, plat)),
'arch': os.path.join(dependency_dir, u'%s_%s_%s' % (ver, plat, arch))
}
def add_dependency(name, first=False):
"""
Accepts a dependency name and automatically adds the appropriate path
to sys.path, if the dependency has a path for the current platform and
architecture.
:param name:
A unicode string name of the dependency
:param first:
If the path should be added to the beginning of the list
"""
dep_paths = generate_dependency_paths(name)
for path in dep_paths.values():
if os.path.exists(encode(path)):
add(path, first=first)
add_dependency('pygments')
add_dependency('backrefs')
add_dependency('markupsafe')
add_dependency('python-markdown')
add_dependency('python-jinja2')
add_dependency('mdpopups')
Restart and enjoy.
Keep in mind that you will have to keep all these separate packages updated on your own.
New BH release. Big change is the that the offscreen bracket popup can now be manually invoked from the command palette (or be bound to a shortcut). The manual command can be run when a single cursor is anywhere between a bracket. If both matching brackets are offscreen, both will be shown in the popup. When binding the command to a shortcut, you can also add the option no_threshold
to auto-search with no threshold before searching for the offscreen brackets, if this is undesirable, this can be done via the unmatched popup dialog on demand.
BracketHighlighter 2.22.0
Released Oct 30, 2016
- NEW: Manual command to show offscreen bracket popup. Can be invoked when cursor is anywhere between target bracket #378
- NEW: When selecting the “Match brackets without threshold” link on the unmatched bracket popup, reshow the offscreen popup.
- NEW: Add support for “SINUMERIK840D” language #379.
As always, report bugs if you find them.
BracketHighlighter 2.23.0
Released Nov 16, 2016
- NEW: Add links in menu to documentation and issues.
- NEW: Provide new local quickstart guide from the menu.
-
NEW: Breaking change to
bh_tag.sublime-settings
.tag_mode
is now an ordered list of dictionaries.
self_closing_patterns
andsingle_tag_patterns
and replaced withoptional_tag_patterns
,
void_tag_patterns
, andself_closing_tag_patterns
. -
NEW: Add new
first_line
rule for determining tag mode. - NEW: New XML tag mode and better XHTML mode.
- NEW: Better special tag logic with handles optional tags, void tags, and self closing tags better. #384
Had too many tags, so BH disappeared from Package Control. I removed some tags, so BH should reappear probably sometime within the next couple of hours.
First off, thank you for a fantastic time saving plugin!
I am having an issue with using <<< in PHP in that it recognizes the last < as a ‘unclosed’ bracket and thus throws off the rest of the bracket highlighting in the code beyond that line. Is there a way to ignore the <<< or make a rule for it? I have tried to use the custom user bracket setting without any luck.
Jeff.
First off, thank you for a fantastic time saving plugin!
You’re welcome .
I am having an issue with using <<< in PHP in that it recognizes the last < as a ‘unclosed’ bracket and thus throws off the rest of the bracket highlighting in the code beyond that line. Is there a way to ignore the <<< or make a rule for it? I have tried to use the custom user bracket setting without any luck.
I’m assuming it’s some kind of operator. I don’t really use PHP, so I am not sure. If it is an operator, and if it is scoped as an operator (or something unique), you can add the scope to be ignored. Pull requests are welcome.
<<< in PHP is used as this example:
un-escaped HTML code with PHP variables like this:
echo <<<HTML
<td bgcolor="$bgcolor" class="info">$sales_name</td>
<td bgcolor="$bgcolor" class="info">$customer_name</td>
<td bgcolor="$bgcolor" class="info">$sample_name2</td>
<td bgcolor="$bgcolor" class="info">$dueback</td>
HTML;
where HTML can be any word you want it to be.
That is just it, I can’t figure out how to make it be ignored If you could show me an example of where to ignore it at, I would be glad to give it a try and will submit a request for it as well.
Thanks for the quick reply!
If you open Preferences > Package Setting BracketHighlighter > Bracket Settings - User and add:
{
"user_brackets": [
{
"name": "angle",
"scope_exclude": [
"string",
"comment",
"keyword.operator",
"punctuation.section.embedded.begin.php",
"source.ruby.rails.embedded.html",
"source.ruby.embedded.html"
],
}
],
}
this should be ignored. However you can also add it as a bracket itself.
Thanks for looking into this @r-stein. Since this resolves the issue, I can push this fix in the next BH version.
I’ll go on to mention if you run into issues like this in the future, you can use a tool like ScopeHunter to analyze the scopes to help you isolate a scope to ignore. There are times when you just can’t do it with scopes though, and then you have to get creative with regex adjustments, and sometimes even python hooks (but those are a little more rare).
So I broke BH on the last tag. It’s been fixed, so if you don’t have 2.23.3, you should probably uprade when available.
Hey, I love BH! Two questions:
-
content_highlight_bar
is great but can we get a styling option for it? I am using a dark theme and it’s almost white, which is way to aggressive for me. Maybe I missed the setting… -
Is there a way to highlight pipes? Here is an example. Focus on the
%>%
operator. Something like the content_highlight_bar would be great for this.
samples <- d %>%
ungroup() %>%
transmute(
test1 = TRUE,
test2 = 1,
test4 = 3,
test4 = "dfgsf") %>%
filter(test2 ==1)
content_highlight_bar is great but can we get a styling option for it? I am using a dark theme and it’s almost white, which is way to aggressive for me. Maybe I missed the setting…
I think it follows the color of the gutter icons, so if the icons are white, the bar is white. I can see the desire to have it a different color, If you create an issue over at the repo, I can look into it moving forward. It’s always been kind of a novelty feature to me that I don’t really use, but I do no there are people who really like it. It’s a bit limited, but it gets the job done .
Is there a way to highlight pipes? Here is an example. Focus on the %>% operator. Something like the content_highlight_bar would be great for this.
Not really sure what you mean by “highlight piples”, can you elaborate?
As far as I can see, “pipes” are just a sort of binary operator and do not have a begin and end token, so I don’t really see how this could be relevant to BH, now what should be done. Maybe you can elaborate?
Yes, they are binary operators without a begin and end token. But they connect a series of calls that can go over many lines. Below is another example from javascript. Having someone like the content_highlight_bar that indicate from where to where the pipe goes could be useful. But I can see that it doesn’t fit into BH
queue()
.defer(d3.json, "/geo/nyc-small.json")
.defer(d3.json, "/geo/nyc-ct.json")
.defer(d3.json, "/geo/nyc-991.json")
.await(function(error, nyc, ctData, calls)
When start and end blocks don’t difference and are not contained within a complete scope and the end caps can be checked (thing string scoping), it is hard for BH to pull off.