From a902788fbf68d7d17ff7598aeb3279ce181b7932 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 23 May 2019 02:38:31 -0400 Subject: [PATCH 1/4] Added `user_swapping` and `user_wrapping` overrides --- bh_swapping.py | 2 +- bh_swapping.sublime-settings | 8 +++++++- bh_wrapping.py | 10 +++++----- bh_wrapping.sublime-settings | 8 +++++++- docs/src/markdown/customize.md | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) 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..c0d80ffd 100644 --- a/bh_swapping.sublime-settings +++ b/bh_swapping.sublime-settings @@ -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..69ba0960 100755 --- a/bh_wrapping.sublime-settings +++ b/bh_wrapping.sublime-settings @@ -74,5 +74,11 @@ {"name": "CSS: @group", "brackets": ["/* @group ${BH_SEL:NAME} */", "/* @end */"], "insert_style": ["block"]} ] } - ] + ], + // 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/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": From 26642b008528fd3d9175c3393df3c7a5920ee67c Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 23 May 2019 03:26:38 -0400 Subject: [PATCH 2/4] Dropped trailing commas --- bh_swapping.sublime-settings | 2 +- bh_wrapping.sublime-settings | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bh_swapping.sublime-settings b/bh_swapping.sublime-settings index c0d80ffd..9de066c3 100644 --- a/bh_swapping.sublime-settings +++ b/bh_swapping.sublime-settings @@ -54,5 +54,5 @@ // 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": [], + "user_swapping": [] } diff --git a/bh_wrapping.sublime-settings b/bh_wrapping.sublime-settings index 69ba0960..4dae01ee 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": [ + "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": "Mardown: Italic", "brackets": ["_", "_${BH_SEL}"]}, + {"name": "Mardown: Monospace", "brackets": ["`", "`${BH_SEL}"]} ] }, { @@ -80,5 +80,5 @@ // 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": [], + "user_swapping": [] } From 573833dda944218b0e52c3b8fd7f1cfc4f61c1a8 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 23 May 2019 03:38:47 -0400 Subject: [PATCH 3/4] fixed typo --- bh_wrapping.sublime-settings | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bh_wrapping.sublime-settings b/bh_wrapping.sublime-settings index 4dae01ee..3973db46 100755 --- a/bh_wrapping.sublime-settings +++ b/bh_wrapping.sublime-settings @@ -75,10 +75,10 @@ ] } ], - // user_swapping will be appended to the tail of swapping + // 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_swapping": [] + "user_wrapping": [] } From 42eb13c3664ec7f2b82c5dec81313f56765777c3 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Fri, 7 Jun 2019 01:27:43 -0400 Subject: [PATCH 4/4] s/Mardown/Markdown/ --- bh_swapping.sublime-settings | 6 +++--- bh_wrapping.sublime-settings | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bh_swapping.sublime-settings b/bh_swapping.sublime-settings index 9de066c3..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}"]} ] }, { diff --git a/bh_wrapping.sublime-settings b/bh_wrapping.sublime-settings index 3973db46..1df593f3 100755 --- a/bh_wrapping.sublime-settings +++ b/bh_wrapping.sublime-settings @@ -39,9 +39,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}"]} ] }, {