Sublime Forum

BracketHighlighter

#159

I can’t seem to get the mouse thing to work at all. The log says it’s firing, but nothing happens. Any ideas?

And thanks to the dev for adding that new always_include_brackets option. :smiley:

0 Likes

#160

@facelessuser

[quote]This is what you need:
{
“name”: “latex_floats”,
“open”: “(\\begin\{(?:table|sidewaystable|figure|sidewaysfigure|algorithm)\})”,
“close”: “(\\end\{(?:table|sidewaystable|figure|sidewaysfigure|algorithm)\})”,
// “open”: “(\begin\{sidewaystable\})”,
// “close”: “(\end\{sidewaystable\})”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “LaTeX”],
“enabled”: true
},
[/quote]

Am I correct in assuming that this will not work with nested constructs? E.g.:

\begin{figure}[thb]
    \begin{center}
         \includegraphics]{Fig_Geometric_Nonlinear_Examples/Roll-up_Dyn/timegeo1.eps}
    \end{center}
\end{figure}

I would think that it would be necessary to include an additional captured group in the open pattern, that was searched for in the close pattern. To try and get this to work I’ve been trying to hook up to the ht/xml tag matching. I tried adding the following (copying //HTML, and modifying the ends of the regex):

// LaTeX \begin{(...)} \end{(...)}
{
    "name": "latex",
    "open": "(\\\\begin\\{)(?=\\w\\:\\-]+(?:(?:\\s+\\w\\-:]+(?:\\s*=\\s*(?:\"^\"]*\"|'^']*'|^>\\s]+))?)*)\\s*\\/?>|\\/\\w\\:\\-]+^>]*\\})",
    "close": "(?<=\\\\end\\{)(?:\\w\\:\\-]+(?:(?:\\s+\\w\\-:]+(?:\\s*=\\s*(?:\"^\"]*\"|'^']*'|^>\\s]+))?)*)\\s*\\/?|\\/\\w\\:\\-]+^>]*)(\\})",
    "style": "tag",
    "scope_exclude": "string", "comment"],
    "language_filter": "whitelist",
    "language_list": "LaTeX"],
    "plugin_library": "bh_modules.tags",
    "find_in_sub_search": "only",
    "enabled": true
},

and then

"tag_mode": {
        "xhtml": "XML", "LaTeX"], ...

But I don’t get anything. I haven’t been able to find info on how to hook up custom tags.

0 Likes

#161

Probably will need to right a bh_plugin.

We have a proprietary language I have to use at work that is similar in this way:

for illustration

def somefunction var1 var2
        if (somecondition)
            some more code;
        eif
edef

So, I define my opening and closing brackets, and then sort out which opening matches to which closing by using a bh_plugin (do until is an exception):
[pre=#232628]def compare(name, first, second, bfr):
opening = bfrfirst.begin:first.end].lower()
closing = bfrsecond.begin:second.end].lower()
match = False
if opening == “do”:
if closing == “until”:
match = True
else:
match = “e” + opening == closing
return match[/pre]

Another example for handling case differences in PHP keywords:
github.com/facelessuser/Bracket … eywords.py

0 Likes

#162

Match when cursor is on outside edge of bracket:
Okay, everyone that has been wanting this, take some time to test the new experimental feature (ST3 only currently)

Add this setting to your “bh_core.sublime-settings”.

"bracket_outside_adjacent": true,

There is going to be some more overhead when this is turned on, but hopefully the impact won’t be too noticeable. I did this for you guys, so please do test and give feedback. If you are waiting for ST2, it may be a tomorrow or the day after.

0 Likes

#163

Few small things:

  1. It seems that this command doesn’t work anymore after the update (and boy, this command is damn useful!):
{ "keys": "ctrl+shift+space"], "command": "bh_key", "args": { "lines" : true, "plugin": { "type": "__all__"], "command": "bh_modules.bracketselect" } } }

The issue is present, with without bracket_outside_adjacent set to either true or false
2) add a different scope for adjacent, so it can have different color

0 Likes

#164
  1. This is now fixed. Funny, it had nothing to do with the new algorithm…just me with a stray mutli-cursor editing something I shouldn’t have.

  2. How come? Current algorithm doesn’t track such things. I would need to pass that info around, and it would require a bit of change to the code. Not sure I really want to spend time on that unless there was a really good reason.

FYI, I know tag outside adjacent just shows angles, I haven’t updated the tag bh_plugin with support yet.

0 Likes

#165

Tag support for experimental outside adjacent is in.

0 Likes

#166

Thanks! I had 3 hours of hell without that! :smiley:

About different highlight: my idea was only in case is an easy thing to do and it aims at certain situations like this:

There are some (probably) rare cases where highlight adjacent it may stay in your way. The idea is to highlight adjacent slightly different AND highlight regular brackets. So in the case i presented in the screenshots, outside brackets should be green, inside brackets should be dark (or light) green (or pink, or whatever i set in the colorscheme). Make sense?

0 Likes

#167

That just means you now appreciate me more :smile:.

Let me think about it. I don’t actually track whether I am catching an adjacent match currently. I inject some stuff to conditionally alter the algorithm to work in these adjacent cases, but it is rarely aware that the final matched brackets are in fact adjacent.

Right now, I am just happy I got it in. I have been putting it off for over a year because I just didn’t want to add more complexity to an already complex system. It really wasn’t as bad as I thought (once I finally spent real time analyzing what would need to be done). I know people have been wanting it though, so hopefully it works well, I figure with enough guinea pigs testing this out, we should hopefully find any overlooked problems.

0 Likes

#168

ST2 Experimental outside adjacent matching has been merged in.

Side note, I may add an additional option to have some bh_plugins ignore the “outside adjacent” setting. Things like pressing select and having it expand does not work with adjacent; instead, it just expands and shrinks over and over :smile:.

0 Likes

#169

Yay! Awesome thanks a lot, much appreciated. At first insight seems to work great, and looks mixed with inside adjacent which is handy. I’ll report back any oddities; I’ve a feature request, (that I have no idea if is complicated or not.)

When I put the cursor in
});|
It would be nice to skip the character “;” and highlight the bracket “)” this is handy for JavaScript. It would be also nice, something similar with “},|” skipping the “,”. But the comma should not be skipped for example with quotes as “aasdasd”,|

Thanks! :slight_smile:

0 Likes

#170

Please do. I am kind of relying on the community to find the issues with this…cause I’m lazy :smile:.

[quote=“tito”]When I put the cursor in
});|
It would be nice to skip the character “;” and highlight the bracket “)” this is handy for JavaScript. It would be also nice, something similar with “},|” skipping the “,”. But the comma should not be skipped for example with quotes as “aasdasd”,|
[/quote]

Its a cool idea, but I will be honest. When I rewrote BH1 to BH2, I did so vowing not to place language specific code in the core code. BH is surprisingly complex (and also something I need to cleanup as it has become pretty complex). The idea was always to allow the definitions to be exposed to the user and expose some kind of plugin system to do bracket manipulation if desired. I did this to take the burden off of me as I was becoming bogged down with language requests and the BH1’s code base just couldn’t handle it, so I threw away pyparadigm’s original code started from scratch and built BH2.

What you suggest can probably be done for javascript in your user folder by excluding the current “)” in javascript and writing a rule like: open = “(()” and close="()(?:;|,)?)" and then run that through a “post_match” event in a bh_plugin adjusting the selection to not include the “;” or “,” if present. This is basically what tags does. Tags just does a simple match for “<” and “>” and then runs it through “post_match” event in the “tag” bh_plugin which determines it is a tag and finds the corresponding open or close matching tag. So, theoretically doable.

0 Likes

#171

Thanks for the information, I’m a little lost on how to configure it to get that behaviour. :blush:, have been trying and watching the settings with no suscess, I also have some fear to break the current behaviour, my settings are just:

{ // Character threshold to search "search_threshold": 50000, "bracket_outside_adjacent": true, "no_multi_select_icons": true, "bracket_styles": { "tag": { "icon": "tag", // "color": "brackethighlighter.tag", "style": "underline" } } }

Oh, another request I just reminded, more important than the previous request; When a tag is outlined, it currently outlines the complete tag. For XML/RDF/XUL files this is somewhat distracting, for example currently the following between brackets is outlined:

<dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">]http://url.tld/N</dcterms:identifier>] It would be nice to just highlitgh the tag name, as

<[dcterms:identifier] rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://url.tld/N</[dcterms:identifier]>
I known( really ??) this may be complicated for the self-closing case ?

<[dcterms:identifier] rdf:resource="http://url.tld"/]>
There are also these infinite opening tags… and that /really/ disturbs

<input onsomething1="yaydaydya1()" onsomething2="yaydaydya2()" onsomething2="yaydaydya3()" onsomething3="yaydaydya4()" onsomething4="yaydaydya5()" onsomething4="yaydaydya6()" onsomething5="yaydaydya7()" onsomething6="yaydaydya8()" onsomething7="yaydaydya9()" />

Could be easily tweaked? I guess you are aware of this

0 Likes

#172

[quote=“tito”]Thanks for the information, I’m a little lost on how to configure it to get that behaviour. , have been trying and watching the settings with no suscess, I also have some fear to break the current behaviour, my settings are just:
CODE: SELECT ALL
{
// Character threshold to search
“search_threshold”: 50000,
“bracket_outside_adjacent”: true,
“no_multi_select_icons”: true,
“bracket_styles”: {
“tag”: {
“icon”: “tag”,
// “color”: “brackethighlighter.tag”,
“style”: “underline”
}
}
}
[/quote]

Lol, yeah, I understand that. It is one of those things that I wanted to be super simple, but it is so configurable that setting it up can be complicated. If I get some time in the next week, I may PM you with the basic idea.

In BH1 I used to have a low profile tag highlight mode

<]input ... />]
<]dcterms:identifier rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">]http://url.tld/N<]/dcterms:identifier>]

I can probably add that back in again pretty easily. Create an issue, and I will look into exposing a tag plugin setting to do this.

0 Likes

#173

Issue added thanks for consideration

0 Likes

#174

Thanks, it may be a bit before I get to it. Not sure yet how much would need to be changed to make this happened (hopefully not too much, but I never know till I get into it). It was straight forward in BH1, but BH1 was less complicated times.

0 Likes

#175

New Feature to help with defining custom rules added (ST3 ONLY).

One of the slightly annoying things about BH is that if you want to try out a custom rule, or modify an existing one, you need to copy the whole default set of rules. If you do this in your User folder, new updates to BH rules will not be picked up until you rebase your rules.

Well, I set out to fix that with some new changes I will outline below:

Let’s say you have a custom language you want to have on your machine. Now, you can simply add it to one of the two settings arrays: “user_scope_brackets” and “user_brackets”:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”:
{
“name”: “mylang”,
“open”: “^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\b”,
“close”: “\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.bh_modules.mylangkeywords”,
“language_filter”: “whitelist”,
“language_list”: “mylang”],
“enabled”: true
}
],[/pre]

Let’s say you want to modify an existing rule, maybe just tweak the language list, all you have to do is use the same name and the item you want to change. Only that attribute will be overridden:
[pre=#232628] “user_brackets”:
// Angle
{
“name”: “angle”,
“language_list”:
“HTML”, “HTML 5”, “XML”, “PHP”, “HTML (Rails)”,
“HTML (Jinja Templates)”, “HTML (Twig)”, “HTML+CFML”,
“ColdFusion”, “ColdFusionCFC”, “laravel-blade”,
“Handlebars”, “AngularJS”,
“SomeNewLanguage” // <— New language
]
}
],[/pre]

Let’s say I want to insert a new rule between two rules. I can turn on debug mode and call the BracketHighlighter: (Debug) Filter Rules by Key then select position to see the current rule order and their postion index:

[pre=#232628]

    {"name": "curly", "position": 0},
    {"name": "round", "position": 1},
    {"name": "square", "position": 2},
    {"name": "html", "position": 3},
    {"name": "cfml", "position": 4},
    {"name": "php_angle", "position": 5},
    {"name": "angle", "position": 6},
    {"name": "cssedit_groups", "position": 7},
    {"name": "ruby_embedded_html", "position": 8},
    {"name": "ruby", "position": 9},
    {"name": "c_compile_switch", "position": 10},
    {"name": "php_keywords", "position": 11},
    {"name": "erlang", "position": 12},
    {"name": "bash", "position": 13},
    {"name": "fish", "position": 14},
    {"name": "mylang", "position": 15}
],

    {"name": "py_single_quote", "position": 0},
    {"name": "py_double_quote", "position": 1},
    {"name": "single_quote", "position": 2},
    {"name": "double_quote", "position": 3},
    {"name": "jsregex", "position": 4},
    {"name": "perlregex", "position": 5},
    {"name": "rubyregex", "position": 6},
    {"name": "mditalic", "position": 7},
    {"name": "mdbold", "position": 8}
]

][/pre]

Then you can specify the position you want to insert at:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”:
{
“name”: “mylang”,
“position”: 4, // <-- New position
“open”: “^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\b”,
“close”: “\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.bh_modules.mylangkeywords”,
“language_filter”: “whitelist”,
“language_list”: “mylang”],
“enabled”: true
}
],[/pre]

And if you run the debug command again, you will see that the position has changed:

[pre=#232628] {“name”: “curly”, “position”: 0},
{“name”: “round”, “position”: 1},
{“name”: “square”, “position”: 2},
{“name”: “html”, “position”: 3},
{“name”: “trex”, “position”: 4}, // <-- New position
{“name”: “cfml”, “position”: 5},
{“name”: “php_angle”, “position”: 6},[/pre]

This can be used to adjust the position of default rules from your user settings as well as shown by overrides above.

So, unless you are forking BH to pull request a change to the default rules, you can now modify the rules all in these two settings without copying or touching the default rules:

[pre=#232628] “user_scope_brackets”: ],
“user_brackets”: ],[/pre]

This will allow you to make changes, but still receive new updated rules.

**Debug mode is a setting in the settings file. Toggling debug mode via command palette only changes the settings in memory, so when you save the settings file, it reverts back to the original. I choose not to save it automatically to the settings file so as not to regenerate the settings file and erase all the comments in the settings file. If you want to put the plugin in a more “hard” debug mode, set “debug” to “true” manually in your settings file.

0 Likes

#176

Hello!

Sorry if this is the wrong place to ask for this.

I love this plugin, but I lack, err, the artistic eye (reason I don’t do website design) so am having a hard time making visually appealing colour choices
and highlighting styles for myself. If anyone could share their relevant settings for a dark backgrounds I’d appreciate it. :smile:

Sorry for the inconvenience. :blush:

0 Likes

#177

A couple of new additions (ST3 Only):

Content Bar
This is an experimental content bar. This is a feature that has been requested a number of times, but I have held off due to Sublime’s limitations. I have added recently only as an experiment, but I may keep it around. This is experimental and not guaranteed to stick around and its features/behavior are subject to change. The future of this feature depends on the feedback I get, so please do give feedback: negative or positive.

So This experimental feature exists in two forms. The first can be seen by enabling the new “content_highlight_bar” setting. This will draw a line highlighting a brackets content at the start of the line. This has the lowest overhead and works with monospace fonts and proportional fonts.

So the second form has a bit more overhead and probably only works well on monospace fonts. This form draws the content bar at the brackets indentation level. It can not draw the line across empty spaces, and I currently do not draw the line if text comes before the line (this is illustrated in the first example below). Feature requires “content_highight_bar” and “align_content_highlight_bar” to be set to true.

Toggle Brackets
This feature is made possible by some changes made to the “bracketselect” bh_plugin. By setting up the selection key binding as shown below, instead of jumping through nested brackets in just one direction, this binding will toggle between the opening and closing of the current bracket only:

[pre=#232628] {
“keys”: “ctrl+m”],
“command”: “bh_key”,
“args”:
{
“no_outside_adj”: true,
“lines” : true,
“plugin”:
{
“type”: “all”],
“command”: “bh_modules.bracketselect”,
“args”: {“select”: “right”, “alternate”: true}
}
}
},[/pre]

Anyways hope you enjoy, and please leave feedback about the experimental content bar feature.

0 Likes

#178

Hi, Im just wondering if the brackets(open n close) is not highlighted does that mean that there is something wrong with the codes in the brackets? because i have something like this:

if()
{
  if()
  {
     
  }
  else
  {

  }
}

the second ifs curly brackets and else are highlighted but the first ifs curly bracket doesnt get highlighted.

0 Likes