Sublime Forum

ST3: BracketHighlighter 2

#61

It just looks a bit odd when the popup shows different coloring to the view, I prefer consistency… In Bracket Highlighter’s case, I don’t think it matters that pygments supports more languages out the box because the current view has to be highlighted by a Sublime Text syntax definition anyway, (BH does nothing in Plain Text mode by default) and thus I believe it is reasonable to assume that the necessary syntax definition is up-to-date and desired over pygments.

0 Likes

#62

True, but that consideration was made on a whole. In general mdpopups doesn’t look at the view style. That was a recent addition for this BH feature.

0 Likes

#63

Iterating over this some more today. BH can now detect brackets off screen vertically and horizontally.

The code highlighting is nice, but it can break depending what context is grabbed. Like if you truncate a line or other things. So I am trying something a little different. Now BH will grab context lines around the the off screen bracket and show those too. But instead of syntax highlighting everything, just the bracket is emphasized.

This hasn’t been released yet as I have to polish it up, but let me know what you think.

3 Likes

#64

I was wondering how you’d achieve syntax highlighting for part of a file. I had the idea that it could be done using the add_regions API, applying the full scope on a character by character basis - which is hardly ideal performance wise. I like your solution, because it is the bracket that needs to be emphasized anyway so syntax highlighting for the context isn’t as important :slightly_smiling:

0 Likes

#65

Thanks, it seemed to make more sense. I really didn’t like that the bracket wasn’t emphasized. And it isn’t easy to highlight characters and syntax highlight. But you are right that code fragments just don’t highlight well as you really need to break at certain token boundaries.

So the way it is working now is that if you have a bracket vertically off screen, you will get 2 lines of context: usually 1 before the main line and 1 after (though if there are no lines before or after, the additional line can be shifted as you see in the posted images).

Horizontal off screen brackets are on the same line as the on screen, so no additional lines are shown, but you will see the bracket emphasized on the current line.

0 Likes

#66

2.18.6 has been released with the latest fixes/improvements. As soon as it is available on Package Control, you guys can start playing with it.

2 Likes

#67

Oh, I didn’t mention it, but now you can configure number of context lines, number of context chars per line, and even the emphasis color of the bracket in the popup (you can use standard TextMate scopes or hex colors – see the settings file for more info). I haven’t had a chance to regen the official docs, but the settings file is pretty descriptive.

1 Like

#68

2.20.0 due to positive reception of the new popups, they are now out of experimentation and turned on by default for ST 3116+.

  • Bracket emphasis in popups is now calculated from bracket styles, but you can re-enable custom bracket configuration via the setting: use_custom_popup_bracket_emphasis.

  • On BH upgrade, BH will attempt to have Package control update dependencies when it is aware dependencies are behind.

1 Like

#69

Anyone know how to install BracketHighlighter v2.20.0 manually? not via Package Control.

0 Likes

#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