diff --git a/bh_swapping.py b/bh_swapping.py index 7e042caf..2804eed3 100755 --- a/bh_swapping.py +++ b/bh_swapping.py @@ -70,7 +70,7 @@ def run(self, edit, async=False): self.async = async self.window = self.view.window() - self.wrap = SwapBrackets(self.view, "bh_swapping.sublime-settings", "swapping") + self.wrap = SwapBrackets(self.view, "bh_swapping.sublime-settings", "swapping", "user_swapping") if len(self.wrap._menu): self.window.show_quick_panel( diff --git a/bh_swapping.sublime-settings b/bh_swapping.sublime-settings index ab6b791b..93076987 100644 --- a/bh_swapping.sublime-settings +++ b/bh_swapping.sublime-settings @@ -27,9 +27,9 @@ }, { "enabled": true, "language_list": ["Markdown", "Multimarkdown", "GithubFlavoredMarkdown", "Markdown Extended"], "language_filter": "whitelist", "entries": [ - {"name": "Mardown: Bold", "brackets": ["**", "**${BH_SEL}"]}, - {"name": "Mardown: Italic", "brackets": ["_", "_${BH_SEL}"]}, - {"name": "Mardown: Monospace", "brackets": ["`", "`${BH_SEL}"]} + {"name": "Markdown: Bold", "brackets": ["**", "**${BH_SEL}"]}, + {"name": "Markdown: Italic", "brackets": ["_", "_${BH_SEL}"]}, + {"name": "Markdown: Monospace", "brackets": ["`", "`${BH_SEL}"]} ] }, { @@ -48,5 +48,11 @@ {"name": "C/C++: #ifndef, #else", "brackets": ["#ifndef${BH_SEL}", "#else\n${BH_TAB:/* CODE */}\n#endif"]} ] } - ] + ], + // user_swapping will be appended to the tail of swapping + // If you have custom rules that you don't want to commit to + // the official list, and do not need to be inserted before + // one of the official definitions, this is a good place to + // put yours rules and keep in sync with the defaults. + "user_swapping": [] } diff --git a/bh_wrapping.py b/bh_wrapping.py index f2e45926..9a444d47 100755 --- a/bh_wrapping.py +++ b/bh_wrapping.py @@ -100,7 +100,7 @@ def run(self, edit): class WrapBrackets(object): """Wrap the current selection(s) with the defined wrapping options.""" - def __init__(self, view, setting_file, attribute): + def __init__(self, view, setting_file, attribute, user_attribute): """Initialization.""" self.view = view @@ -108,7 +108,7 @@ def __init__(self, view, setting_file, attribute): self._brackets = [] self._insert = [] self._style = [] - self.read_wrap_entries(setting_file, attribute) + self.read_wrap_entries(setting_file, attribute, user_attribute) def inline(self, edit, sel): """Inline wrap.""" @@ -230,13 +230,13 @@ def select(self, edit): elif len(final_sel): self.view.sel().add(final_sel[0]) - def read_wrap_entries(self, setting_file, attribute): + def read_wrap_entries(self, setting_file, attribute, user_attribute): """Read wrap entries from the settings file.""" settings = sublime.load_settings(setting_file) syntax = self.view.settings().get('syntax') language = splitext(basename(syntax))[0].lower() if syntax is not None else "plain text" - wrapping = settings.get(attribute, []) + wrapping = settings.get(attribute, []) + settings.get(user_attribute, []) for i in wrapping: if not exclude_entry(i["enabled"], i["language_filter"], i["language_list"], language): for j in i.get("entries", []): @@ -302,7 +302,7 @@ def run(self, edit): self._brackets = [] self._insert = [] self._style = [] - self.read_wrap_entries("bh_wrapping.sublime-settings", "wrapping") + self.read_wrap_entries("bh_wrapping.sublime-settings", "wrapping", "user_wrapping") if len(self._menu): self.view.window().show_quick_panel( diff --git a/bh_wrapping.sublime-settings b/bh_wrapping.sublime-settings index 6d01798e..1df593f3 100755 --- a/bh_wrapping.sublime-settings +++ b/bh_wrapping.sublime-settings @@ -38,10 +38,10 @@ ] }, { - "enabled": true, "language_list": ["Markdown", "Multimarkdown", "GithubFlavoredMarkdown", "Markdown Extended"], "language_filter": "whitelist", "entries": [ - {"name": "Mardown: Bold", "brackets": ["**", "**${BH_SEL}"]}, - {"name": "Mardown: Italic", "brackets": ["_", "_${BH_SEL}"]}, - {"name": "Mardown: Monospace", "brackets": ["`", "`${BH_SEL}"]} + "enabled": true, "language_list": ["Markdown", "Multimarkdown", "GithubFlavoredMarkdown", "Markdown Extended"], "language_filter": "whitelist", "entries": [ + {"name": "Markdown: Bold", "brackets": ["**", "**${BH_SEL}"]}, + {"name": "Markdown: Italic", "brackets": ["_", "_${BH_SEL}"]}, + {"name": "Markdown: Monospace", "brackets": ["`", "`${BH_SEL}"]} ] }, { @@ -74,5 +74,11 @@ {"name": "CSS: @group", "brackets": ["/* @group ${BH_SEL:NAME} */", "/* @end */"], "insert_style": ["block"]} ] } - ] + ], + // user_wrapping will be appended to the tail of swapping + // If you have custom rules that you don't want to commit to + // the official list, and do not need to be inserted before + // one of the official definitions, this is a good place to + // put yours rules and keep in sync with the defaults. + "user_wrapping": [] } diff --git a/docs/src/markdown/customize.md b/docs/src/markdown/customize.md index c4eca866..0575a4e1 100644 --- a/docs/src/markdown/customize.md +++ b/docs/src/markdown/customize.md @@ -676,7 +676,7 @@ Parameters | Description ### Bracket Rule Management -In the past, BracketHighlighter required a user to copy the entire bracket list to the user `bh_core.sublime-settings` file. This was a cumbersome requirement that also punished a user because if they did this, they wouldn't automatically get updates to the rules as all the rules were now overridden by the user's settings file. +In the past, BracketHighlighter required a user to copy the entire bracket list to the user `bh_core.sublime-settings`/`bh_swapping.sublime-settings`/`bh_wrapping.sublime-settings` file. This was a cumbersome requirement that also punished a user because if they did this, they wouldn't automatically get updates to the rules as all the rules were now overridden by the user's settings file. BracketHighlighter now lets you add or modify existing rules without overriding the entire rule set, or even the entire target rule. Let's say you have a custom language you want to have on your machine. Now, you can simply add it to one of the two settings arrays: "user_scope_brackets" and "user_brackets":