Permalink
Browse files

-Add support for opening and closing bracket icons when opening and

closing bracket is not on the same line.
-optiomize pngs
  • Loading branch information...
1 parent 1b6ddba commit 6e49ba5cf21c481b0077321413449408f1a32c19 @facelessuser committed Oct 27, 2012
Showing with 154 additions and 98 deletions.
  1. +1 −1 Example.sublime-keymap
  2. +107 −74 bh_core.py
  3. +34 −8 bh_core.sublime-settings
  4. +12 −15 bh_modules/swapquotes.py
  5. BIN icons/angle_bracket_close.png
  6. BIN icons/angle_bracket_close_small.png
  7. BIN icons/angle_bracket_open.png
  8. BIN icons/angle_bracket_open_small.png
  9. BIN icons/angle_bracket_small.png
  10. BIN icons/bookmark_small.png
  11. BIN icons/circle_small.png
  12. BIN icons/curly_bracket_close.png
  13. BIN icons/curly_bracket_close_small.png
  14. BIN icons/curly_bracket_open.png
  15. BIN icons/curly_bracket_open_small.png
  16. BIN icons/curly_bracket_small.png
  17. BIN icons/dot_small.png
  18. BIN icons/double_quote.png
  19. BIN icons/double_quote_close.png
  20. BIN icons/double_quote_close_small.png
  21. BIN icons/double_quote_offset.png
  22. BIN icons/double_quote_offset_open.png
  23. BIN icons/double_quote_offset_open_small.png
  24. BIN icons/double_quote_offset_small.png
  25. BIN icons/double_quote_open.png
  26. BIN icons/double_quote_open_small.png
  27. BIN icons/double_quote_small.png
  28. BIN icons/question.png
  29. BIN icons/question_small.png
  30. BIN icons/quote_small.png
  31. BIN icons/round_bracket_close.png
  32. BIN icons/round_bracket_close_small.png
  33. BIN icons/round_bracket_open.png
  34. BIN icons/round_bracket_open_small.png
  35. BIN icons/round_bracket_small.png
  36. BIN icons/single_offset_quote .png
  37. BIN icons/single_quote.png
  38. BIN icons/single_quote_close.png
  39. BIN icons/single_quote_close_small.png
  40. BIN icons/single_quote_offset_open.png
  41. BIN icons/single_quote_offset_open_small.png
  42. BIN icons/single_quote_offset_small.png
  43. BIN icons/single_quote_open.png
  44. BIN icons/single_quote_open_small.png
  45. BIN icons/single_quote_small.png
  46. BIN icons/square_bracket_close.png
  47. BIN icons/square_bracket_close_small.png
  48. BIN icons/square_bracket_open.png
  49. BIN icons/square_bracket_open_small.png
  50. BIN icons/square_bracket_small.png
View
@@ -113,7 +113,7 @@
"lines" : true,
"plugin":
{
- "type": ["quote", "pyquote"],
+ "type": ["single_quote", "double_quote", "py_single_quote", "py_double_quote"],
"command": "bh_modules.swapquotes"
}
}
View
@@ -71,16 +71,35 @@ def select_bracket_style(option):
def select_bracket_icons(option, settings):
icon = ""
small_icon = ""
+ open_icon = ""
+ small_open_icon = ""
+ close_icon = ""
+ small_close_icon = ""
icon_path = settings.get("icon_path", "Theme - Default").replace('\\', '/').strip('/')
# Icon exist?
- if (
- exists(normpath(join(sublime.packages_path(), icon_path, option + ".png"))) and
- not option == "none" and not option == ""
- ):
- icon = "../%s/%s" % (icon_path, option)
+ if not option == "none" and not option == "":
+ if exists(normpath(join(sublime.packages_path(), icon_path, option + ".png"))):
+ icon = "../%s/%s" % (icon_path, option)
if exists(normpath(join(sublime.packages_path(), icon_path, option + "_small.png"))):
small_icon = "../%s/%s" % (icon_path, option + "_small")
- return icon, small_icon
+ if exists(normpath(join(sublime.packages_path(), icon_path, option + "_open.png"))):
+ open_icon = "../%s/%s" % (icon_path, option + "_open")
+ else:
+ open_icon = icon
+ if exists(normpath(join(sublime.packages_path(), icon_path, option + "_open_small.png"))):
+ small_open_icon = "../%s/%s" % (icon_path, option + "_open_small")
+ else:
+ small_open_icon = small_icon
+ if exists(normpath(join(sublime.packages_path(), icon_path, option + "_close.png"))):
+ close_icon = "../%s/%s" % (icon_path, option + "_close")
+ else:
+ close_icon = icon
+ if exists(normpath(join(sublime.packages_path(), icon_path, option + "_close_small.png"))):
+ small_close_icon = "../%s/%s" % (icon_path, option + "_close_small")
+ else:
+ small_close_icon = small_icon
+
+ return icon, small_icon, open_icon, small_open_icon, close_icon, small_close_icon
def exclude_bracket(enabled, filter_type, language_list, language):
@@ -237,14 +256,19 @@ def __init__(self, bracket, settings, default_highlight):
self.name = bracket["name"]
self.color = bracket.get("color", default_highlight["color"])
self.selections = []
+ self.open_selections = []
+ self.close_selections = []
self.compare = bracket.get("compare")
self.find_in_sub_search = bracket.get("find_in_sub_search", False)
self.post_match = bracket.get("post_match")
self.scope_exclude_exceptions = bracket.get("scope_exclude_exceptions", [])
self.scope_exclude = bracket.get("scope_exclude", [])
self.style = select_bracket_style(bracket.get("style", default_highlight["style"]))
self.underline = self.style & sublime.DRAW_EMPTY_AS_OVERWRITE
- self.icon, self.small_icon = select_bracket_icons(bracket.get("icon", default_highlight["icon"]), settings)
+ (
+ self.icon, self.small_icon, self.open_icon,
+ self.small_open_icon, self.close_icon, self.small_close_icon
+ ) = select_bracket_icons(bracket.get("icon", default_highlight["icon"]), settings)
self.ignore_string_escape = bracket.get("ignore_string_escape", False)
self.no_icon = ""
@@ -254,6 +278,8 @@ def __init__(self, bracket, settings, default_highlight):
self.open = re.compile("\\A" + bracket.get("open", "."), re.MULTILINE | re.IGNORECASE)
self.close = re.compile(bracket.get("close", ".") + "\\Z", re.MULTILINE | re.IGNORECASE)
self.selections = []
+ self.open_selections = []
+ self.close_selections = []
self.name = bracket["name"]
self.color = bracket.get("color", default_highlight["color"])
sub_search = bracket.get("sub_bracket_search", "false")
@@ -264,7 +290,10 @@ def __init__(self, bracket, settings, default_highlight):
self.scopes = bracket["scopes"]
self.style = select_bracket_style(bracket.get("style", default_highlight["style"]))
self.underline = self.style & sublime.DRAW_EMPTY_AS_OVERWRITE
- self.icon, self.small_icon = select_bracket_icons(bracket.get("icon", default_highlight["icon"]), settings)
+ (
+ self.icon, self.small_icon, self.open_icon,
+ self.small_open_icon, self.close_icon, self.small_close_icon
+ ) = select_bracket_icons(bracket.get("icon", default_highlight["icon"]), settings)
self.no_icon = ""
@@ -441,9 +470,13 @@ def init_match(self):
else:
for b in (self.brackets + [self.incomplete]):
b.selections = []
+ b.open_selections = []
+ b.close_selections = []
for s in self.scopes:
for b in s["brackets"]:
b.selections = []
+ b.open_selections = []
+ b.close_selections = []
def get_bracket_type(self, name, begin, end):
entry = None
@@ -483,35 +516,38 @@ def change_sel(self):
self.view.sel().clear()
map(lambda x: self.view.sel().add(x), self.sels)
+ def highlight_regions(self, name, icon_type, selections, bracket, regions):
+ if len(selections):
+ self.view.add_regions(
+ name,
+ getattr(bracket, selections),
+ bracket.color,
+ getattr(bracket, icon_type),
+ bracket.style
+ )
+ regions.append(name)
+
def highlight(self, view):
for region_key in self.view.settings().get("bh_regions", []):
self.view.erase_regions(region_key)
regions = []
icon_type = "no_icon"
+ open_icon_type = "no_icon"
+ close_icon_type = "no_icon"
if not self.no_multi_select_icons or not self.multi_select:
icon_type = "small_icon" if self.view.line_height() < 16 else "icon"
+ open_icon_type = "small_open_icon" if self.view.line_height() < 16 else "open_icon"
+ close_icon_type = "small_close_icon" if self.view.line_height() < 16 else "close_icon"
for b in (self.brackets + [self.incomplete]):
- if len(b.selections):
- self.view.add_regions(
- "bh_" + b.name,
- b.selections,
- b.color,
- getattr(b, icon_type),
- b.style
- )
- regions.append("bh_" + b.name)
+ self.highlight_regions("bh_" + b.name, icon_type, "selections", b, regions)
+ self.highlight_regions("bh_" + b.name + "_open", open_icon_type, "open_selections", b, regions)
+ self.highlight_regions("bh_" + b.name + "_close", close_icon_type, "close_selections", b, regions)
for s in self.scopes:
for b in s["brackets"]:
- if len(b.selections):
- self.view.add_regions(
- "bh_" + b.name,
- b.selections,
- b.color,
- getattr(b, icon_type),
- b.style
- )
- regions.append("bh_" + b.name)
+ self.highlight_regions("bh_" + b.name, icon_type, "selections", b, regions)
+ self.highlight_regions("bh_" + b.name + "_open", open_icon_type, "open_selections", b, regions)
+ self.highlight_regions("bh_" + b.name + "_close", close_icon_type, "close_selections", b, regions)
self.view.settings().set("bh_regions", regions)
def get_search_bfr(self, sel):
@@ -577,37 +613,33 @@ def match(self, view, force_match=True):
if self.count_lines:
sublime.status_message('In Block: Lines ' + str(self.lines) + ', Chars ' + str(self.chars))
- def find_scopes(self, bfr, sel):
- # Search buffer
- left, right, bracket, sub_matched = self.match_scope_brackets(bfr, sel)
- if sub_matched:
- return True
- regions = [sublime.Region(sel.a, sel.b)]
-
- if left is not None and right is not None:
- left, right, regions = self.run_plugin(bracket.name, left, right, regions)
- if left is None and right is None:
- return True
+ def save_incomplete_regions(self, left, right, regions):
+ found = left if left is not None else right
+ bracket = self.incomplete
+ if bracket.underline:
+ bracket.selections += underline((found.toregion(),))
+ else:
+ bracket.selections += [found.toregion()]
+ self.store_sel(regions)
- if left is not None and right is not None:
- if self.count_lines:
- self.chars += abs(right.begin - left.end)
- self.lines += abs(self.view.rowcol(right.begin)[0] - self.view.rowcol(left.end)[0] + 1)
- if bracket.underline:
+ def save_regions(self, left, right, bracket, regions):
+ lines = abs(self.view.rowcol(right.begin)[0] - self.view.rowcol(left.end)[0] + 1)
+ if self.count_lines:
+ self.chars += abs(right.begin - left.end)
+ self.lines += lines
+ if bracket.underline:
+ if lines <= 1:
bracket.selections += underline((left.toregion(), right.toregion()))
else:
+ bracket.open_selections += underline((left.toregion(),))
+ bracket.close_selections += underline((right.toregion(),))
+ else:
+ if lines <= 1:
bracket.selections += [left.toregion(), right.toregion()]
- self.store_sel(regions)
- return True
- elif left is not None or right is not None:
- found = left if left is not None else right
- bracket = self.incomplete
- if bracket.underline:
- bracket.selections += underline((found.toregion(),))
else:
- bracket.selections += [found.toregion()]
- return True
- return False
+ bracket.open_selections += [left.toregion()]
+ bracket.close_selections += [right.toregion()]
+ self.store_sel(regions)
def sub_search(self, sel, search_window, bfr, scope=None):
bracket = None
@@ -621,14 +653,27 @@ def sub_search(self, sel, search_window, bfr, scope=None):
# Matched brackets
if left is not None and right is not None and bracket is not None:
- if self.count_lines:
- self.chars += abs(right.begin - left.end)
- self.lines += abs(self.view.rowcol(right.begin)[0] - self.view.rowcol(left.end)[0] + 1)
- if bracket.underline:
- bracket.selections += underline((left.toregion(), right.toregion()))
- else:
- bracket.selections += [left.toregion(), right.toregion()]
- self.store_sel(regions)
+ self.save_regions(left, right, bracket, regions)
+ return True
+ return False
+
+ def find_scopes(self, bfr, sel):
+ # Search buffer
+ left, right, bracket, sub_matched = self.match_scope_brackets(bfr, sel)
+ if sub_matched:
+ return True
+ regions = [sublime.Region(sel.a, sel.b)]
+
+ if left is not None and right is not None:
+ left, right, regions = self.run_plugin(bracket.name, left, right, regions)
+ if left is None and right is None:
+ return True
+
+ if left is not None and right is not None:
+ self.save_regions(left, right, bracket, regions)
+ return True
+ elif left is not None or right is not None:
+ self.save_incomplete_regions(left, right, regions)
return True
return False
@@ -644,23 +689,11 @@ def find_matches(self, bfr, sel):
# Matched brackets
if left is not None and right is not None and bracket is not None:
- if self.count_lines:
- self.chars += abs(right.begin - left.end)
- self.lines += abs(self.view.rowcol(right.begin)[0] - self.view.rowcol(left.end)[0] + 1)
- if bracket.underline:
- bracket.selections += underline((left.toregion(), right.toregion()))
- else:
- bracket.selections += [left.toregion(), right.toregion()]
- self.store_sel(regions)
+ self.save_regions(left, right, bracket, regions)
# Unmatched brackets
elif left is not None or right is not None:
- found = left if left is not None else right
- bracket = self.incomplete
- if bracket.underline:
- bracket.selections += underline((found.toregion(),))
- else:
- bracket.selections += [found.toregion()]
+ self.save_incomplete_regions(left, right, regions)
def escaped(self, pt, ignore_string_escape, scope):
if not ignore_string_escape:
View
@@ -24,10 +24,10 @@
"scope_brackets": [
// Quotes
{
- "name": "pyquote",
- "open": "u?r?((?:\"\")?\"|(?:'')?')",
- "close": "((?:\"\")?\"|(?:'')?')",
- "icon": "quote",
+ "name": "py_single_quote",
+ "open": "u?r?((?:'')?')",
+ "close": "((?:'')?')",
+ "icon": "single_quote",
"color": "brackethighlighter.quote",
"style": "underline",
"scopes": ["string"],
@@ -37,10 +37,36 @@
"enabled": true
},
{
- "name": "quote",
- "open": "(\"|')",
- "close": "(\"|')",
- "icon": "quote",
+ "name": "py_double_quote",
+ "open": "u?r?((?:\"\")?\")",
+ "close": "((?:\"\")?\")",
+ "icon": "double_quote",
+ "color": "brackethighlighter.quote",
+ "style": "underline",
+ "scopes": ["string"],
+ "language_filter": "whitelist",
+ "language_list": ["Python"],
+ "sub_bracket_search": "true",
+ "enabled": true
+ },
+ {
+ "name": "single_quote",
+ "open": "(')",
+ "close": "(')",
+ "icon": "single_quote",
+ "color": "brackethighlighter.quote",
+ "style": "underline",
+ "scopes": ["string"],
+ "language_filter": "blacklist",
+ "language_list": ["Plain text"],
+ "sub_bracket_search": "true",
+ "enabled": true
+ },
+ {
+ "name": "double_quote",
+ "open": "(\")",
+ "close": "(\")",
+ "icon": "double_quote",
"color": "brackethighlighter.quote",
"style": "underline",
"scopes": ["string"],
View
@@ -18,30 +18,27 @@ def run(self, edit, name):
return
new = "'" if (quote == '"') else '"'
old = quote
- begin = self.left.begin + 1
- end = self.right.end
+ begin = self.left.end
+ end = self.right.begin
content_end = self.right.begin
- while begin < end:
+
+ view.replace(edit, self.left.toregion(), view.substr(self.left.toregion()).replace(old, new))
+ view.replace(edit, self.right.toregion(), view.substr(self.right.toregion()).replace(old, new))
+
+ offset = 0
+ while begin < end + offset:
char = view.substr(begin)
if char == old and self.escaped(begin - 1):
view.replace(edit, sublime.Region(begin - 1, begin), '')
- end -= 1
+ offset -= 1
content_end -= 1
elif char == new and not self.escaped(begin - 1):
view.insert(edit, begin, "\\")
- end += 1
+ offset += 1
content_end += 1
begin += 1
- if name == "pyquote" and self.left.size() == 3:
- view.replace(edit, self.left.toregion(), new * 3)
- else:
- view.replace(edit, sublime.Region(self.left.begin, self.left.begin + 1), new)
- if name == "pyquote" and self.right.size() == 3:
- view.replace(edit, sublime.Region(content_end, end), new * 3)
- else:
- view.replace(edit, sublime.Region(content_end, end), new)
-
- self.right = self.right.move(content_end, end)
+
+ self.right = self.right.move(content_end, end + offset)
self.selection = [sublime.Region(content_end)]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN icons/question.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN icons/question_small.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
View
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
View
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.

0 comments on commit 6e49ba5

Please sign in to comment.