Sublime Forum

BracketHighlighter2 BETA Branch

#121

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.
[pre=#2D2D2D] // 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
}
],[/pre]

Lastly, you create a file called phpkeywords.py in your ST2 User folder with this code:
[pre=#2D2D2D]def compare(name, first, second, bfr):
return “end” + bfrfirst.begin:first.end].lower() == bfrsecond.begin:second.end].lower()[/pre]

If I remember, I will add this by default into BracketHighlighter tonight.

0 Likes

#122

PHP Conditional Keyword highlighting is now officially on the Beta Branch.

0 Likes

#123

It not really works…

This example works:

<? foreach ($key as $val) : echo $val; endforeach; ?>

but this not:

[code]<? foreach ($key as $val) : ?>

<?=$val;?>
<? endforeach; ?> [/code]
0 Likes

#124

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):

{ "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:

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 (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:

if ( true ) then null; end if;

Thanks for any help!

0 Likes

#125

[quote=“peter222”]It not really works…

This example works:

<? foreach ($key as $val) : echo $val; endforeach; ?>

but this not:

[code]<? foreach ($key as $val) : ?>

<?=$val;?>
<? endforeach; ?> [/code][/quote]

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.

({)(})

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.

// 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.

0 Likes

#126

[quote=“rogenaro”]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):

{ "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:

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 (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:

if ( true ) then null; end if;

Thanks for any help![/quote]

I will take a look when I have some time.

0 Likes

#127

@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:

[pre=#2D2D2D] // 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
}[/pre]

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.

0 Likes

#128

Thanks, @facelessuser, that did the trick!

0 Likes

#129

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.

0 Likes

#130

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

0 Likes

#131

Did you restart ST2 after installing? Also, please list how you installed it.

0 Likes

#132

I did restart ST2.

I already had BracketHighlighter installed and I used the info in this thread for upgrading in Package Control
http://www.sublimetext.com/forum/viewtopic.php?f=5&t=9756&start=60#p38968.

I am assuming it should work the same for select Ruby statements as is does for brace/bracket matching.

For example, when my cursor is on the inside of a “do” the matching “end” would be highlighted.

0 Likes

#133

Have you verified it actually updated? If you look in Pakckages/BracketHighlighter it should no longer have BracketHighlighter.sublime-settings, but have bh_core.sublime-settings etc.

Also, please post an example of the code it isn’t working in; it is working fine for me in ST2.

0 Likes

#134

It did update. BracketHighlighter.sublime-settings is gone and I have bh_core.sublime-settings.

And I just realized what is happening. I am in my RSpec unit test code. Even though it contains valid ruby code, BracketHighlighter probably does not recognize the do/end blocks nested in the RSpec context constructs. When I go to some standard Ruby code the matching works… which ROCKS!!!

Is there a way I can add the RSpec constructs? (e.g describe/end | it/end | context/end |before/end )

In case your not familiar with RSpec… the code files end with .rb and the word “_spec” is added to the file name. So if I have a Ruby class file named “game.rb” the RSpec tests are defined in a file named “game_spec.rb.”

BTW this is tutorial code, not prod code…

[code]
require_relative ‘movie’

describe Movie do
before do
@init_rank = 10
@movie = Movie.new(“goonies”, @init_rank)
end
it “has a capitalized title” do
@movie.title.should == “Goonies”
end
it “has an initial rank” do
@movie.rank.should == @init_rank
end

context "created with a default rank" do
	before do
		@movie = Movie.new("goonies")	
	end
	it "has a rank of 0" do
		@movie.rank.should == 0
	end
end

context "with a rank of at least 10" do
  before do
		@movie = Movie.new("goonies", 10)	
  end
  it "is a hit" do
  	@movie.should be_hit
  end
  it "has a 'hit' status" do
  	@movie.status.should == "Hit"
  end
end

context "with a rank less than 10" do
  before do
		@movie = Movie.new("goonies")	
  end
  it "is a flop" do
  	@movie.should_not be_hit
  end
  it "has a 'flop' status" do
  	@movie.status.should == "Flop"
  end
end

end[/code]

0 Likes

#135

I really don’t know what the difference between ruby and rspec is since I do coding in neither, but copying the code into a ruby file, it worked fine. I imagine your rspec files are not using the ruby sytanx highlighter but some other rspec syntax highlighter? If so, you need to add the appropriate syntax highlighter to your ruby config object in bh_core.sublime-settings

[pre=#2D2D2D] // Ruby conditional statements
{
“name”: “ruby”,
“open”: “(^\s*\b(?:if|case|until|unless|while|begin|class|module|def\b\s*[a-zA-Z_[/color]\d]+)|do)\b”,
“close”: “\b(end)\b”,
“style”: “default”,
“scope_exclude”: “string”, “comment”],
“plugin_library”: “bh_modules.rubykeywords”,
“language_filter”: “whitelist”,
“language_list”: “Ruby”, “Ruby on Rails”, “HTML (Rails)”],
“enabled”: true
},[/pre]

0 Likes

#136

Interesting… Okay I will look into that.

Thanks and great job on the plugin. You’ve helped make our jobs easier!

-Chris

0 Likes

#137

No problem.

I procrastinated doing BH2 for a long time, but I am glad it is done now. It really has helped for a lot of cool added stuff.

0 Likes