Sublime Forum

BracketHighlighter2 BETA Branch

#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

#21

I will make the ruby post_match plugin official. If this works good for you.

0 Likes

#22

Man, you’re tireless. :smiley:
It’s working.
Im sure there’ll be other exotic problems to solve with ruby being expressive as it’s, but you clearly prooved the flexibility of BH2.

0 Likes

#23

you might want to update open pattern to
[pre=#212121]“open”: “(^\s*\b(?:if|until|unless|while|begin|class|module|def\b\s*[a-zA-Z_]+)|do)\b”[/pre]
to account for this side effect

Also i vote 1+ for styles extracted and reused across definitions.

0 Likes

#24

[quote=“vitaLee”]you might want to update open pattern to
[pre=#212121]“open”: “(^\s*\b(?:if|until|unless|while|begin|class|module|def\b\s*[a-zA-Z_]+)|do)\b”[/pre]
to account for this side effect
[attachment=0]Screen shot 2012-10-23 at 22.42.21.png[/attachment]
[/quote]

Great! Thanks for your help on this. I haven’t coded in ruby so it is nice to have help nailing it down.

[quote=“vitaLee”]
Also i vote 1+ for styles extracted and reused across definitions.[/quote]

That is the good thing about this being an alpha; in an alpha I can change everything and say “I told it you it was an alpha”. Beta I don’t have that much flexibility. I am thinking it would make more sense with separate style objects. I will have to see how much I have to change in the algorithm to make that happen. I will see if anyone else chimes in as well.

0 Likes

#25

Ruby fixes are in.

Still tinkering with the styles. Separating the styles doesn’t really reduce the number of style stuff by much, it just puts it in a separate place. The regions are made up of the whole combination of icon, color, and highlight style, so they really need to be one package. So even if you use the same color and highlight style, having different icons still means having separate style objects. And I really don’t think I am looking for an overly complicated styling system either. I will play with it in the next couple of days, and hopefully role something out. I think the separation is good, I just don’t think its going to amount to great reduction of stuff in the config file.

That is how it goes though; you want something highly configurable, sometimes the downside is you have to configure that stuff every time.

0 Likes

#26

I either found a small bug or i don’t get it right.
So, in my bh_wrapping file (inside user folder) i added this:

{ "enabled": true, "language_list": "HTML", "HTML 5", "XML", "PHP", "ColdFusion", "ColdFusionCFC"], "language_filter": "whitelist", "entries": {"name": "HTML/XML Tag", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"]}, {"name": "HTML/XML Tag - Block", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"], "insert_style": "block"}, {"name": "HTML/XML Tag - Block Indent", "brackets": "<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"], "insert_style": "indent_block"}, {"name": "PHP Tags", "brackets": "<?php${BH_SEL}", "?>"], "insert_style": "indent_block"}, {"name": "PHP Tags", "brackets": "<?php${BH_SEL}", "?>"], "insert_style": "block"} ] },

What i would like is to highlight pairs of <?php ?> tags. What do i do wrong?

Thanks!

0 Likes

#27

bracket pair definitions are within bh_core.sublime-settings.
i imagine there’ll be conflicts with already defined pairs containing angle brackets though.

0 Likes

#28

Nah, you should be able to define php no problem. I will post in a bit (if the forum lets me; I think it is breaking down again).

0 Likes

#29

Just paste the php define before tags. Order counts in the settings file.

[pre=#2D2D2D] // PHP enclosure
{
“name”: “php_enclosure”,
“open”: “(<\?php)”,
“close”: “(\?>)”,
“icon”: “angle”,
“color”: “brackethighlighter.angle”,
“style”: “underline”,
“language_filter”: “whitelist”,
“scope_exclude”: “string”, “comment”, “keyword.operator”],
“language_list”: “HTML”, “HTML 5”, “XML”, “PHP”, “HTML+CFML”, “ColdFusion”, “ColdFusionCFC”],
“enabled”: true
},
// HTML Tags
{
“name”: “tag”,
“open”: “(<)”,
“close”: “(>)”,
“icon”: “tag”,
“color”: “brackethighlighter.tag”,
“style”: “outline”,
“language_filter”: “whitelist”,
“scope_exclude”: “string”, “comment”, “keyword.operator”],
“language_list”: “HTML”, “HTML 5”, “XML”, “PHP”, “HTML+CFML”, “ColdFusion”, “ColdFusionCFC”],
“plugin_library”: “bh_modules.tags”,
“enabled”: true
},[/pre]

0 Likes

#30

@facelessuser is that a custom color scheme you’re using?
care to share?

0 Likes

#31

Man, you are awesome! Thanks a lot, now looks beautiful! :smile:

Btw, there is a way we can reward you for the awesome job you do? A paypal account maybe? :wink:

0 Likes