Skip to content

Instantly share code, notes, and snippets.

@ProtractorNinja
Last active December 17, 2015 12:18
Show Gist options
  • Save ProtractorNinja/5608300 to your computer and use it in GitHub Desktop.
Save ProtractorNinja/5608300 to your computer and use it in GitHub Desktop.
A plugin for BracketHighlighter for Sublime Text 2 that escapes from a bracketed block. Based on the bracketselect plugin.
import bh_plugin
import sublime
DEFAULT_TAGS = ["cfml", "html", "angle"]
class BlockEscape(bh_plugin.BracketPluginCommand):
def run(self, edit, name, tags=DEFAULT_TAGS):
current_left, current_right = self.selection[0].begin(), self.selection[0].end()
left, right = self.left, self.right
first, last = left.end, right.begin
if left.end != right.end:
if name in tags and left.size() > 1:
first, last = right.begin + 1, right.begin + 1
if first == current_left and last == current_right:
first, last = right.end, right.end
else:
first, last = right.begin, right.begin
if first == current_left and last == current_right:
first, last = right.end, right.end
else:
# There is no second bracket, so just select the first
if name in tags and left.size() > 1:
first, last = left.begin + 1, left.begin + 1
else:
first, last = right.end, right.end
if first == current_left and last == current_right:
first, last = right.end, right.end
self.selection = [sublime.Region(first+1, last+1)]
def plugin():
return BlockEscape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment