Home Download Buy Blog Forum Support

BracketHighlighter2 BETA Branch

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 4:36 pm

iamntz wrote: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 ;)

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?


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.
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby vitaLee on Tue Oct 23, 2012 5:21 pm

Great update!!! :)
Havent checked the options in detail but played around with Ruby brackets marking.
Screen shot 2012-10-23 at 19.58.50.png
Screen shot 2012-10-23 at 19.58.50.png (16.32 KiB) Viewed 1514 times

after that updated the open pattern to
            "open": "^\\s*\\b(if|until|while|begin|class|module|def\\s*[a-zA-Z_]+)\\b",

but then how do i define new pattern to match do-end block as in
Screen shot 2012-10-23 at 20.08.28.png
Screen shot 2012-10-23 at 20.08.28.png (10.2 KiB) Viewed 1513 times

if i define new bracket definition as simple as
{
"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
},

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.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 5:46 pm

vitaLee wrote:Great update!!! :)
Havent checked the options in detail but played around with Ruby brackets marking.
Screen shot 2012-10-23 at 19.58.50.png

after that updated the open pattern to
            "open": "^\\s*\\b(if|until|while|begin|class|module|def\\s*[a-zA-Z_]+)\\b",


Cool, I will update that.

vitaLee wrote:but then how do i define new pattern to match do-end block as in
Screen shot 2012-10-23 at 20.08.28.png

if i define new bracket definition as simple as
{
"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
},

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.

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.
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby vitaLee on Tue Oct 23, 2012 5:56 pm

missed unless
"open": "^\\s*\\b(if|unless|until|while|begin|class|module|def\\s*[a-zA-Z_]+)\\b"
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 6:01 pm

@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
def post_match(view, name, first, second, center, bfr, threshold):
bracket_name = "rubydo" if bfr[first.begin:first.end] == "do" else name
return first, second, bracket_name


Define "do" in the original ruby, and create a "rubydo" after that as seen below.
        // 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
},


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.
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 6:03 pm

That is a little trick I am doing right now for angle brackets and tags.
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby vitaLee on Tue Oct 23, 2012 6:43 pm

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

3.times do |i|
puts 'hip hip!!!'
end
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 6:46 pm

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"):
        // 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
},


And then you have style objects:
    "styles": {
"ruby": {
"icon": "dot",
"style": "underline",
"color": "brackethighlighter.ruby"
},
"rubydo": {
"icon": "dot",
"style": "underline",
"color": "brackethighlighter.rubydo"
}
// More styles here...
}


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?
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 6:47 pm

vitaLee wrote: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

3.times do |i|
puts 'hip hip!!!'
end


Oh, I see that is tricky. Let me think about that some more.
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Tue Oct 23, 2012 7:08 pm

I cannot be stopped :). Try this:

User/rubykeywords.py
import re


def post_match(view, name, first, second, center, bfr, threshold):
open_bracket = bfr[first.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


And lastly the bracket define (only one is needed now)
        // 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
},



This shows how flexible it is :).
facelessuser
 
Posts: 1564
Joined: Tue Apr 05, 2011 7:38 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests