Sublime Forum

ST3: BracketHighlighter 2

#70

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).

0 Likes

#71

@Neokidesu

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:

Get the latest BracketHighlighter release and unpack as 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.

1 Like

#72

Thanks for answering this method has helped me a lot.

0 Likes

#73

No problem. Glad it helped.

0 Likes

#74

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.

1 Like

#75

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 and single_tag_patterns and replaced with optional_tag_patterns,
    void_tag_patterns, and self_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
0 Likes

#76

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.

0 Likes

#77

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.

0 Likes

#78

First off, thank you for a fantastic time saving plugin!

You’re welcome :slightly_smiling:.

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.

0 Likes

#79

<<< 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 :frowning: 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!

0 Likes

#80

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.

3 Likes

#81

Thank you very much for the quick reply; saved me from going bonkers!

0 Likes

#82

Thanks for looking into this @r-stein. Since this resolves the issue, I can push this fix in the next BH version.

0 Likes

#83

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).

0 Likes

#84

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.

0 Likes

#85

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)
0 Likes

#86

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 :slight_smile:.

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?

0 Likes

#87

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?

1 Like

#88

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)
0 Likes

#89

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.

0 Likes