Home Download Buy Blog Forum Support

BracketHighlighter2 BETA Branch

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Mon Nov 26, 2012 4:24 pm

That was an old post, some things have changed since. I would try something like this in your bh_core.sublime-settings file (make a copy of it in your ST2 User folder and edit the User copy):

You can see here, I have added the PHP conditional keywords definition after the C/C++ compile switches under the setting entitled brackets.
        // C/C++ compile switches
{
"name": "c_compile_switch",
"open": "(\\#(?:if|ifdef|ifndef))\\b",
"close": "(\\#endif)\\b",
"style": "default",
"scope_exclude": ["string", "comment"],
"language_filter": "whitelist",
"language_list": ["C++", "C"],
"enabled": true
},
// PHP conditional keywords
{
"name": "php_keywords",
"open": "^\\s*\\b(if|foreach|for|while|switch)\\b(?=.*:$)",
"close": "^\\s*\\b(endif|endfor|endforeach|endwhile|endswitch)\\b(?=;$)",
"style": "default",
"language_filter": "whitelist",
"scope_exclude": ["string", "comment"],
"plugin_library": "User.phpkeywords",
"language_list": ["HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"],
"enabled": true
}
],


Lastly, you create a file called phpkeywords.py in your ST2 User folder with this code:
def compare(name, first, second, bfr):
return "end" + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()


If I remember, I will add this by default into BracketHighlighter tonight.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Tue Nov 27, 2012 2:30 am

PHP Conditional Keyword highlighting is now officially on the Beta Branch.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby peter222 on Tue Nov 27, 2012 9:56 am

It not really works...

This example works:
Code: Select all
<?
foreach ($key as $val) :
echo $val;
endforeach;
?>


but this not:

Code: Select all
<? foreach ($key as $val) : ?>
<div><?=$val;?></div>
<? endforeach; ?>
Linux Mint 13
peter222
 
Posts: 21
Joined: Tue Jan 03, 2012 11:14 pm

Re: BracketHighlighter2 BETA Branch

Postby rogenaro on Tue Nov 27, 2012 1:21 pm

I've been trying to add some PL/SQL support, but I'm having trouble with the settings.

The settings I'm using are (based on the PHP settings):
Code: Select all
        {
            "name": "plsql_keywords",
            "open": "^\\s*\\b(if)\\b",
            "close": "^\\s*\\b(end if)\\b",
            "style": "default",
            "language_filter": "whitelist",
            "scope_exclude": ["string", "comment"],
            "plugin_library": "User.plsqlkeywords",
            "language_list": ["SQL", "PL/SQL (Oracle)"],
            "enabled": true
        }


The plsqlkeywords.py file in my user directory has:
Code: Select all
def compare(name, first, second, bfr):
   print name
   return "end " + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()


(I was trying to print the parameters so I could get a better general understanding of it's workings)

However, BH2 is not able to call the plugin defined in the plugin_library parameter, no matter what.

In order to identify what I'm doing wrong, I'd like to clarify some things:
- In the language_list parameter array, I should use the language name defined in the .tmLanguage file, right?
- I'm using bizoo's package (https://github.com/bizoo/Oracle), so in my case the language name should be "PL/SQL (Oracle)". I'm assuming that there's no need to escape the forward slash (I've tried renaming the language name, but without success)
- I've also tried to simplify the open and close regexes to the point of just "(.)", but even in this case the plugin is not called. Could anyone clarify me on what I could be doing wrong?

the code I'm using to test is this:
Code: Select all
if ( true ) then
  null;
end if;


Thanks for any help!
rogenaro
 
Posts: 2
Joined: Tue Nov 27, 2012 12:54 pm

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Tue Nov 27, 2012 3:06 pm

peter222 wrote:It not really works...

This example works:
Code: Select all
<?
foreach ($key as $val) :
echo $val;
endforeach;
?>


but this not:

Code: Select all
<? foreach ($key as $val) : ?>
<div><?=$val;?></div>
<? endforeach; ?>


Well, it works, but you don't quite understand the rules. PHP has some quirks.

This is simply a case of dangling brackets. You can see here that the curly braces are not actually matches.
Code: Select all
({)(})


The algorithm is very general in BracketHighlighter so that it works with all languages. Stuff like this is a bit tricky to deal with without making some concessions.

So, I have updated the PHP Conditional Keywords on the Beta branch, but in order for this to work for you, you have to ignore <?, <?php, and ?>. If you do this, those will no longer be highlighted, but BracketHighlighter will be able to see things like the foreach and endforeach across the <? ?> punctuation.

So update your BH2 branch and then change your Angle definition to match this in your User/bh_core.sublime-settings file.

Code: Select all
        // Angle
        {
            "name": "angle",
            "open": "(<)",
            "close": "(>)",
            "style": "angle",
            "scope_exclude": ["string", "comment", "keyword.operator", "punctuation.section.embedded.end.php", "punctuation.section.embedded.begin.php"],
            "language_filter": "whitelist",
            "language_list": ["HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"],
            "plugin_library": "bh_modules.tags",
            "enabled": true
        },


That is the best I can do for you.

Edit: I am sure other things can break this like comments right before or right after the php punctuation, but if someone wants to take the time to code up the "perfect" regex, I will pull it in, but this should work in most cases; not sure if there will be any side effects when ignoring <? and ?>. This isn't guaranteed to be perfect, I kind of expect the community to polish up the regex for their languages and save me from trying to come up with the regex for every language that I might not even use.
Last edited by facelessuser on Tue Nov 27, 2012 3:29 pm, edited 1 time in total.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Tue Nov 27, 2012 3:10 pm

rogenaro wrote:I've been trying to add some PL/SQL support, but I'm having trouble with the settings.

The settings I'm using are (based on the PHP settings):
Code: Select all
        {
            "name": "plsql_keywords",
            "open": "^\\s*\\b(if)\\b",
            "close": "^\\s*\\b(end if)\\b",
            "style": "default",
            "language_filter": "whitelist",
            "scope_exclude": ["string", "comment"],
            "plugin_library": "User.plsqlkeywords",
            "language_list": ["SQL", "PL/SQL (Oracle)"],
            "enabled": true
        }


The plsqlkeywords.py file in my user directory has:
Code: Select all
def compare(name, first, second, bfr):
   print name
   return "end " + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()


(I was trying to print the parameters so I could get a better general understanding of it's workings)

However, BH2 is not able to call the plugin defined in the plugin_library parameter, no matter what.

In order to identify what I'm doing wrong, I'd like to clarify some things:
- In the language_list parameter array, I should use the language name defined in the .tmLanguage file, right?
- I'm using bizoo's package (https://github.com/bizoo/Oracle), so in my case the language name should be "PL/SQL (Oracle)". I'm assuming that there's no need to escape the forward slash (I've tried renaming the language name, but without success)
- I've also tried to simplify the open and close regexes to the point of just "(.)", but even in this case the plugin is not called. Could anyone clarify me on what I could be doing wrong?

the code I'm using to test is this:
Code: Select all
if ( true ) then
  null;
end if;


Thanks for any help!


I will take a look when I have some time.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Tue Nov 27, 2012 4:34 pm

@rogenaro you weren't far off at all. The problem was simply that the language name you see in the bottom right hand corner of the window is not always the name you use. You actually use the name of the tmLanguage file, which in your case is PL_SQL (Oracle).tmLanguage so the final definition would look like this:

        // Oracle conditional keywords
{
"name": "plsql_keywords",
"open": "^\\s*\\b(if)\\b",
"close": "^\\s*\\b(end if)\\b",
"style": "default",
"language_filter": "whitelist",
"scope_exclude": ["string", "comment"],
"plugin_library": "User.plsqlkeywords",
"language_list": ["SQL", "PL_SQL (Oracle)"],
"enabled": true
}


The ST2 always returns the name of the language internally as the name of the tmLanguage file, not the friendly name you see in the bottom right hand corner of your window; sometimes these match up, but in your case they do not.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby rogenaro on Tue Nov 27, 2012 7:57 pm

Thanks, @facelessuser, that did the trick!
rogenaro
 
Posts: 2
Joined: Tue Nov 27, 2012 12:54 pm

Re: BracketHighlighter2 BETA Branch

Postby facelessuser on Mon Jan 07, 2013 5:17 pm

Just to let everyone know, I am not dead, and am still planning on releasing this soonish, but I haven't had the time and such to finish up yet. Been real busy, and had some stuff come up that has prevented my work on this plugin. I am hoping to finish up documentation within the next two weeks, and hopefully get Package Control messages working and I should be ready to release it.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 BETA Branch

Postby simspace on Fri Mar 01, 2013 5:03 pm

I just upgraded the BracketHighlighter plugin in ST2 so I can use the new Ruby functionality. I used the upgrade instruction from a prior post in this thread.

The upgrade appears to have been successful but Ruby matching (e.g. do/end) does not appear to be working for me. I'm guessing it's a config issue on my part but I'm not sure where to start.

I've been reading the threads here, but I hesitate to make the changes described in the earlier November post since there have probably been some significant code changes in the past three months.

I'd appreciate any advice or direction to get the Ruby matching working.

Thanks,
Chris
simspace
 
Posts: 6
Joined: Wed Jul 11, 2012 6:44 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 10 guests