Sublime Forum

BracketHighlighter2 BETA Branch

#1

I have a branch up for the BracketHighlighter2 Alpha. I still need to add some missing features (mainly swapping brackets), but most everything else is in.

There is no real good documentation yet, and only an example keymap file. BH2 will not use your old BH settings file. Remember to restart ST2 if you update to this branch.

I have support for a number of different language bracket stuff, but I haven’t documented yet how to set them up, but you can use the current ones as an example and play around.

Scope based brackets (which should only be done if there is no good way to reliably capture the brackets with regex; quotes is a good example of this), has a small caveat where if you have the same type right next to each other, they will bleed together. This isn’t usually a problem for most brackets though. You never really but two strings together like this "first string "“second string”, you would just do this “first string second string”. This goes for most others as well. I did originally try and allow limiters on the scope so you could limit the left side with a certain scope and the right side with a certain scope, but ST2’s extract_scope API command proved disappointing and was only marginally useful. If there ends up being a real need for scope limiters, I will add them back, but for now, the scope brackets are basic in their implementation.

Branch is here:
github.com/facelessuser/Bracket … r/tree/BH2

Feel free to post bugs, suggestions, feedback (good or bad). This is meant to replace the current BracketHighlighter, so go ahead and make your opinion known now during development before I push this out as official.

0 Likes

Change color of HTML attributes of form tags
#2

Looks good, thanks for the update! It’s good to see that brackets are not highlighted unless the cursor is inside. :mrgreen:

It’s possible to have the highlight as i had it before? That is a nice green box that surrounded the brackets? (current outline is a little different).

Also, it’s possible to turn on/off highlight style for all types at all? From what i figured out, i have to go and change every single style.

Thanks!

0 Likes

#3

Yes it is. The styles are the same as before (underline|solid|outline). Colors are done the same as before as well. You just need to define the scope. By default I am using scopes that probably don’t exist in your theme. You can either define those scopes in your theme with the green color you want, or use a scope that is in your theme file that uses the green color. Before I had it defaulted to something like “entity.class” or something close to that. You can check the current BH1 branch to see what those defaults were.

But in short, just set “style” and “color” to your liking for each bracket entry.

Can you elaborate? Do you mean you want to disable all bracket highlighting in one shot? I can add that if that is what you want.

0 Likes

#4

Before it was doing by default what Pyparadigm had it originally set up (which mimicked ST2)…but when I was re-writing, I thought it made more sense to do inside brackets only. Someone had suggested it to me a while back, can’t remember who, but I liked it so much it has become the way moving forward.

0 Likes

#5

Why the hell would i want to disable this awesome plugin??? :open_mouth:
Ok, so, right now, if I want to change style from underline (which is default) to solid (like i want), i have to edit bb_core.sublime-settings and do a replace all. This leads to a lot of code duplication (i’ll have 99% identical code in the BH folder and user settings folder). The idea is to avoid this kind of duplication:

"brackets": 
    // Basic brackets
    {
        "name": "curly",
        "open": "(\\{)",
        "close": "(\\})",
    >>> "style": "solid", <<<<
    },
    {
        "name": "round",
        "open": "(\\()",
        "close": "(\\))",
    >>> "style": "solid", <<<<
    },
    {
        "name": "square",
        "open": "(\\)",
        "close": "(\\])",
    >>> "style": "solid", <<<<
    }
]

And switch all styles at once. Some kind of master of all :smile:

Namely to get rid of this „issue” :smile: Make sense?

0 Likes

#6

Ahh. I got it now.

What I will do is add a global style object that will have a default icon, style, and color in it. If you want an entry to pick up something from the global object, you will just not define it in the bracket definition.

So in your case, you would remove the color and style parameter from all of the bracket definitions to pick up the global style and color. That way, people who like different styles for different brackets can still define separate colors and styles, and people who like one consistent color and style can just remove the overrides.

I will try and add that tomorrow. Thanks for the input.

0 Likes

#7

Alright @iamntz, got your change in.

So now you can define these default parameters:
[pre=#2D2D2D] // Global defaults to use if a bracket does not define its own
“default_icon”: “dot”,
“default_style”: “underline”,
“default_color”: “brackethighlighter.default”,[/pre]

And then you can have a bracket pick up using them by removing there override paramater. So for example, If I have a curly bracket that I want to pick up the default color and style, I would simply just remove the override parameters like in the example below:

[pre=#2D2D2D] // Basic brackets
{
“name”: “curly”,
“open”: “(\{)”,
“close”: “(\})”,
“icon”: “curly_bracket”,
// “color”: “brackethighlighter.curly”,
// “style”: “underline”,
“scope_exclude”: “string”, “comment”],
“scope_exclude_exceptions”: “string.other.math.block.environment.latex”],
“language_filter”: “blacklist”,
“language_list”: “Plain text”],
“find_in_sub_search”: true,
“ignore_string_escape”: true,
“enabled”: true
},[/pre]

This way allows you to change the default, and all the brackets pick up the change if they haven’t overridden the defaults.

0 Likes

#8

Thanks for the update. Seems to work good, although i was talking about some kind of master switch, but it’s ok afterall. I guess :smiley:

How do i change highlight colours though? I have this in my thTheme file but nothing happen (also restarted the editor)
(http://img.iamntz.com/jing/2012-10-23_1623.png)

(i have no idea if i set up the old colours or was default to that beautiful green :smile: )

Thanks!

0 Likes

#9

@iamntz

So you wanted like a force_default_style_use switch? I can add that as well if you like. Just let me know.

Yeah, ST2’s configuration of region colors is kind of lame, so it makes it that much more confusing.
It looks like you are using Monokai, so doing nothing in the old version would yield green. That is because the default for the old BH was "entity.name.class"
So if you change your default to “entity.name.class”. And make the rest pick it up, you should get green.
[pre=#2D2D2D] // Global defaults to use if a bracket does not define its own
“default_icon”: “dot”,
“default_style”: “solid”,
“default_color”: “entity.name.class”,[/pre]

Or you can define it in the bracket definition:
[pre=#2D2D2D] // Quotes
{
“name”: “pyquote”,
“open”: “u?r?((?:”")?"|(?:’’)?’)",
“close”: “((?:”")?"|(?:’’)?’)",
“icon”: “quote”,
“color”: “entity.name.class”,
“style”: “underline”,
“scopes”: “string”],
“language_filter”: “whitelist”,
“language_list”: “Python”],
“sub_bracket_search”: “true”,
“enabled”: true
},[/pre]

In order to configure it via the theme file, you have to use the entire scope. By default I am using the scope namespace of “brackethighlighter”, so that must be included as well. Here is an example from mine.
[pre=#2D2D2D]
name
Bracket Curly
scope
brackethighlighter.curly
settings

foreground
#CC99CC



name
Bracket Round
scope
brackethighlighter.round
settings

foreground
#FFCC66

[/pre]

I hope that makes sense.

0 Likes

#10

Totally make sense! Thanks, works just beautiful!

The force_default_style switch would be nice, but wait for others and see what’ they says to not work only for one crazy dude :wink:

But a nice switch to add would be a default color. Because adding 15 entries in tmTheme that set the very same color it might be slightly… wrong?

0 Likes

#11

[quote=“iamntz”]Totally make sense! Thanks, works just beautiful!

The force_default_style switch would be nice, but wait for others and see what’ they says to not work only for one crazy dude :wink:

But a nice switch to add would be a default color. Because adding 15 entries in tmTheme that set the very same color it might be slightly… wrong?[/quote]

It is only wrong if you don’t want different colors. The scopes in the settings file right now are really on examples. BH2 does not require a user to add anything to the theme file, or even use those scops, that is an option that is available for those who want absolute control of their color (like I do). By default, I set each to scopes that don’t exist in most themes, which will default to a the foreground color. If a user would like to define those, or use something different, they are welcome to it. Since the plugin is still in development, the settings file reflects what I have been doing in testing.

I realize because I am defining a number of different scopes in the settings file, a user will feel they need to add these to the themes. I will push out an update later that will simply define them all to “brackethighlighter.default”. Then if some one wants a different colors for a specific brackets, they can define it and change it to whatever they want. The settings file is just a suggestion. Ideally people will just copy it to their user folder and tweak it to there liking.

0 Likes

#12

Great update!!! :smile:
Havent checked the options in detail but played around with Ruby brackets marking.


after that updated the open pattern to
[pre=#212121] “open”: “^\s*\b(if|until|while|begin|class|module|def\s*[a-zA-Z_]+)\b”,[/pre]
but then how do i define new pattern to match do-end block as in


if i define new bracket definition as simple as
[pre=#212121]{
“name”: “ruby”,
“open”: “\b(do)\b”,
“close”: “\b(end)\b”,
“icon”: “dot”,
“color”: “keyword”,
“style”: “underline”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},[/pre]
if it’s placed before default definition then do-end blocks get matched but all other defined with open pattern above fail, and on the flip side if i define this after default definition then do-end blocks are not matched.
i guess it’s because both definitions share the same close pattern.

0 Likes

#13

[quote=“vitaLee”]Great update!!! :smile:
Havent checked the options in detail but played around with Ruby brackets marking.
[attachment=1]Screen shot 2012-10-23 at 19.58.50.png[/attachment]
after that updated the open pattern to
[pre=#212121] “open”: “^\s*\b(if|until|while|begin|class|module|def\s*[a-zA-Z_]+)\b”,[/pre]
[/quote]

Cool, I will update that.

[quote=“vitaLee”]
but then how do i define new pattern to match do-end block as in
[attachment=0]Screen shot 2012-10-23 at 20.08.28.png[/attachment]
if i define new bracket definition as simple as
[pre=#212121]{
“name”: “ruby”,
“open”: “\b(do)\b”,
“close”: “\b(end)\b”,
“icon”: “dot”,
“color”: “keyword”,
“style”: “underline”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},[/pre]
if it’s placed before default definition then do-end blocks get matched but all other defined with open pattern above fail, and on the flip side if i define this after default definition then do-end blocks are not matched.
i guess it’s because both definitions share the same close pattern.[/quote]

Right now, it would have to be included in your original Ruby pattern. This is simply something I didn’t think about. They are combined in one regex (each bracket definition should only have one capturing group), that group id is used to identify what pair the brackets are from. Then I resolve all of the brackets until I find the matching pair.

There is kind of a way around it, but it would require a bracket plugin. I may try and in some additional support for such cases in the future, but I will post a way you can resolve this with a plugin as a stop gap solution.

0 Likes

#14

missed unless
[pre=#212121]“open”: “^\s*\b(if|unless|until|while|begin|class|module|def\s*[a-zA-Z_]+)\b”[/pre]

0 Likes

#15

@vitaLee, try this: this will make all ruby keywords underlined, but do will be outlined.

Put this in your User folder for now as rubykeywords.py
[pre=#2D2D2D]def post_match(view, name, first, second, center, bfr, threshold):
bracket_name = “rubydo” if bfrfirst.begin:first.end] == “do” else name
return first, second, bracket_name[/pre]

Define “do” in the original ruby, and create a “rubydo” after that as seen below.
[pre=#2D2D2D] // Ruby conditional statements
{
“name”: “ruby”,
“open”: “^\s*\b(if|until|while|begin|class|module|do|def\s*[a-zA-Z_]+)\b”,
“close”: “\b(end)\b”,
“icon”: “dot”,
“color”: “keyword”,
“style”: “underline”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.rubykeywords”,
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},
{
“name”: “rubydo”,
“open”: “^\s*\b(do)\b”,
“close”: “\b(end)\b”,
“icon”: “dot”,
“color”: “keyword”,
“style”: “outline”,
“scope_exclude”: “string”, “comment”],
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},[/pre]

You can extend this concept to break out as many as you want. I do assume that if too many separate kinds of brackets are defined for one sytntax file, that you could theoretically hit a limit, but even if you split all of the ruby keywords into their own separate one, you probably wouldn’t hit it.

Hopefully in the future I can fix it so that BH will be smart enough to resolve these kinds of things without the need of a plugin.

0 Likes

#16

That is a little trick I am doing right now for angle brackets and tags.

0 Likes

#17

i kinda get what you mean but i think it wont work because as i understand, for this to work rubydo’s open pattern should be a subexpression of it’s predecessor’s open pattern.
but do will always be preceeded by more than just whitespace and not anchored to bol.
not sure if i got it right, but can you try to match this do-end with your solution

[pre=#212121]3.times do |i|
puts ‘hip hip!!!’
end[/pre]

0 Likes

#18

Would it make more sense to separate styles from bracket definitions?

For instance, you have some definition pointing to a style object (in this case a style object called “ruby”):
[pre=#2D2D2D] // Ruby conditional statements
{
“name”: “ruby”,
“open”: “^\s*\b(if|unless|until|while|begin|class|module|do|def\s*[a-zA-Z_]+)\b”,
“close”: “\b(end)\b”,
“style”: “ruby”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.rubykeywords”,
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},[/pre]

And then you have style objects:
[pre=#2D2D2D] “styles”: {
“ruby”: {
“icon”: “dot”,
“style”: “underline”,
“color”: “brackethighlighter.ruby”
},
“rubydo”: {
“icon”: “dot”,
“style”: “underline”,
“color”: “brackethighlighter.rubydo”
}
// More styles here…
}[/pre]

That way you could have one definition and then define many other styles. A post match plugin could simply throw back a style, and you wouldn’t have dummy regex clogging up the system.

What do you guys think?

0 Likes

#19

[quote=“vitaLee”]i kinda get what you mean but i think it wont work because as i understand, for this to work rubydo’s open pattern should be a subexpression of it’s predecessor’s open pattern.
but do will always be preceeded by more than just whitespace and not anchored to bol.
not sure if i got it right, but can you try to match this do-end with your solution

[pre=#212121]3.times do |i|
puts ‘hip hip!!!’
end[/pre][/quote]

Oh, I see that is tricky. Let me think about that some more.

0 Likes

#20

I cannot be stopped :smile:. Try this:

User/rubykeywords.py
[pre=#2D2D2D]import re

def post_match(view, name, first, second, center, bfr, threshold):
open_bracket = bfrfirst.begin:first.end]
if open_bracket != “do”:
m = re.match(r"^(\s*\b)\w\W]*", open_bracket)
if m:
first = first.move(first.begin + m.end(1), first.end)
return first, second, name[/pre]

And lastly the bracket define (only one is needed now)
[pre=#2D2D2D] // Ruby conditional statements
{
“name”: “ruby”,
“open”: “(^\s*\b(?:if|until|unless|while|begin|class|module|def\s*[a-zA-Z_]+)|do)\b”,
“close”: “\b(end)\b”,
“icon”: “dot”,
“color”: “keyword”,
“style”: “underline”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “User.rubykeywords”,
“language_filter”: “whitelist”,
“language_list”: “Ruby”],
“enabled”: true
},[/pre]

This shows how flexible it is :smile:.

0 Likes