Skip to content
Browse files

-Add bracket swap plugin support

  • Loading branch information...
1 parent 0b48825 commit d550cbe7686cde95bfe2960433ce34cf254bc27e @facelessuser committed Nov 24, 2012
Showing with 79 additions and 43 deletions.
  1. +1 −1 Default.sublime-commands
  2. +1 −1 Example.sublime-keymap
  3. +1 −1 Main.sublime-menu
  4. +7 −29 bh_modules/swapbrackets.py
  5. +23 −10 bh_swapping.py
  6. +46 −0 bh_swapping.sublime-settings
  7. +0 −1 readme.md
View
2 Default.sublime-commands
@@ -137,7 +137,7 @@
},
// Not implemented yet
{
- "caption": "BracketHighlighter: Swap Brackets (NOT IMPLEMENTED)",
+ "caption": "BracketHighlighter: Swap Brackets",
"command": "swap_brackets"
},
// Surround selection with brackets from quick panel
View
2 Example.sublime-keymap
@@ -130,7 +130,7 @@
}
}
},
- // Not implemented yet
+ // Swap brackets with another type
{
"keys": ["ctrl+alt+super+e"],
"command": "swap_brackets"
View
2 Main.sublime-menu
@@ -152,7 +152,7 @@
},
// Not implemented yet
{
- "caption": "Swap Brackets (NOT IMPLEMENTED)",
+ "caption": "Swap Brackets",
"command": "swap_brackets"
},
// Surround selection with brackets from quick panel
View
36 bh_modules/swapbrackets.py
@@ -1,35 +1,13 @@
-import bh_plugin
import sublime
+from bh_plugin import ImportModule as ImpMod
+BracketRemove = ImpMod.import_from("bh_modules.bracketremove", "BracketRemove")
-class SwapBrackets(bh_plugin.BracketPluginCommand):
- def calculate_indentation(self, sel):
- # Calculate how far the last bracket is indented
- _, col_position = self.view.rowcol(self.right.begin)
- tab_size = self.view.settings().get("tab_size", 4)
- tab_count = self.view.substr(sublime.Region(self.right.begin - col_position, self.right.begin)).count('\t')
- spaces = col_position - tab_count
- return "\t" * tab_count + "\t" * (spaces / tab_size) + " " * (spaces % tab_size if spaces >= tab_size else spaces)
-
- def run(self, edit, name, brackets=None):
- if brackets is None:
- return
-
- # Prepare selections
- sel = self.selection[0]
- new_sel = [sublime.Region(sel.begin() + len(brackets[0]))]
-
- # Swap the brackets
- self.view.replace(edit, self.right.toregion(), brackets[-1])
- if len(brackets) > 2:
- # Set up indentation and insertion points
- insert_point = self.right.begin
- indent_to_col = self.calculate_indentation(sel)
- for b in reversed(brackets[1:len(brackets) - 1]):
- self.view.replace(edit, sublime.Region(insert_point), b + "\n" + indent_to_col)
- self.view.replace(edit, self.left.toregion(), brackets[0])
-
- self.selection = new_sel
+class SwapBrackets(BracketRemove):
+ def run(self, edit, name, remove_content=False, remove_indent=False, remove_block=False):
+ offset = self.left.toregion().size()
+ self.selection = [sublime.Region(self.left.begin, self.right.begin - offset)]
+ super(SwapBrackets, self).run(edit, name)
def plugin():
View
33 bh_swapping.py
@@ -1,31 +1,44 @@
-import sublime
import sublime_plugin
+import bh_wrapping
+
+
+class SwapBrackets(bh_wrapping.WrapBrackets):
+ def wrap(self, wrap_entry):
+ if wrap_entry < 0:
+ return
+
+ self._style = ["inline"]
+
+ self.brackets = self._brackets[wrap_entry]
+ self.wrap_brackets(0)
class SwapBracketsCommand(sublime_plugin.WindowCommand):
def swap_brackets(self, value):
if value < 0:
return
- options = []
- if len(options) == 0:
- return
+ self.brackets = self.wrap._brackets[value]
self.window.run_command(
- "bh_key", {
+ "bh_key",
+ {
"plugin": {
"type": ["__all__"],
- "command": "bh_modules.swapbrackets",
- "args": {"brackets": options[value]}
+ "command": "bh_modules.swapbrackets"
}
}
)
+ self.wrap.wrap(value)
def run(self):
- options = []
+ view = self.window.active_view()
+ if view is None:
+ return
+ self.wrap = SwapBrackets(view, "bh_swapping.sublime-settings", "swapping")
- if len(options):
+ if len(self.wrap._menu):
self.window.show_quick_panel(
- options,
+ self.wrap._menu,
self.swap_brackets
)
View
46 bh_swapping.sublime-settings
@@ -0,0 +1,46 @@
+{
+ "swapping": [
+ {
+ "enabled": true, "language_list": [], "language_filter": "whitelist", "entries": [
+ {"name": "<> Angle", "brackets": ["<", ">${BH_SEL}"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["Plain text"], "language_filter": "blacklist", "entries": [
+ {"name": "{} Curly", "brackets": ["{", "}${BH_SEL}"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["Plain text"], "language_filter": "blacklist", "entries": [
+ {"name": "() Round", "brackets": ["(", ")${BH_SEL}"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["Plain text"], "language_filter": "blacklist", "entries": [
+ {"name": "[] Square", "brackets": ["[", "]${BH_SEL}"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"], "language_filter": "whitelist", "entries": [
+ {"name": "HTML/XML Tag", "brackets": ["<${BH_SEL:NAME}>", "</${BH_SEL:NAME}>"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["Markdown"], "language_filter": "whitelist", "entries": [
+ {"name": "Mardown: Bold", "brackets": ["**", "**${BH_SEL}"]},
+ {"name": "Mardown: Italic", "brackets": ["_", "_${BH_SEL}"]}
+ ]
+ },
+ {
+ "enabled": true, "language_list": ["C++", "C"], "language_filter": "whitelist", "entries": [
+ {"name": "C/C++: #if", "brackets": ["#if ${BH_SEL}", "#endif"]},
+ {"name": "C/C++: #if, #else", "brackets": ["#if${BH_SEL}", "#else\n${BH_TAB:/* CODE */}\n#endif"]},
+ {"name": "C/C++: #if, #elif", "brackets": ["#if${BH_SEL}", "#elif ${BH_TAB:/* CONDITION */}\n${BH_TAB:/* CODE */}\n#endif"]},
+ {"name": "C/C++: #ifdef", "brackets": ["#ifdef${BH_SEL}", "#endif"]},
+ {"name": "C/C++: #ifdef, #else", "brackets": ["#ifdef${BH_SEL}", "#else\n${BH_TAB:/* CODE */}\n#endif"]},
+ {"name": "C/C++: #ifndef", "brackets": ["#ifndef${BH_SEL}", "#endif"]},
+ {"name": "C/C++: #ifndef, #else", "brackets": ["#ifndef${BH_SEL}", "#else\n${BH_TAB:/* CODE */}\n#endif"]}
+ ]
+ }
+ ]
+}
View
1 readme.md
@@ -4,7 +4,6 @@ This is a fork of pyparadigm's _SublimeBrackets_ and _SublimeTagmatcher_ (both a
<img src="http://dl.dropbox.com/u/342698/BracketHighlighter/Example1.png" border="0">
# TODO
-- Bracket Swap Plugin
- Documentation
# Credits

0 comments on commit d550cbe

Please sign in to comment.
Something went wrong with that request. Please try again.