Skip to content

Commit a4bca4a

Browse files
committed
Added user_swapping and user_wrapping overrides
1 parent 0e1eaac commit a4bca4a

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

bh_swapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def run(self, edit, async=False):
7070

7171
self.async = async
7272
self.window = self.view.window()
73-
self.wrap = SwapBrackets(self.view, "bh_swapping.sublime-settings", "swapping")
73+
self.wrap = SwapBrackets(self.view, "bh_swapping.sublime-settings", "swapping", "user_swapping")
7474

7575
if len(self.wrap._menu):
7676
self.window.show_quick_panel(

bh_swapping.sublime-settings

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@
4747
{"name": "C/C++: #ifndef, #else", "brackets": ["#ifndef${BH_SEL}", "#else\n${BH_TAB:/* CODE */}\n#endif"]}
4848
]
4949
}
50-
]
50+
],
51+
// user_swapping will be appended to the tail of swapping
52+
// If you have custom rules that you don't want to commit to
53+
// the official list, and do not need to be inserted before
54+
// one of the official definitions, this is a good place to
55+
// put yours rules and keep in sync with the defaults.
56+
"user_swapping": [],
5157
}

bh_wrapping.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def run(self, edit):
100100
class WrapBrackets(object):
101101
"""Wrap the current selection(s) with the defined wrapping options."""
102102

103-
def __init__(self, view, setting_file, attribute):
103+
def __init__(self, view, setting_file, attribute, user_attribute):
104104
"""Init."""
105105

106106
self.view = view
107107
self._menu = []
108108
self._brackets = []
109109
self._insert = []
110110
self._style = []
111-
self.read_wrap_entries(setting_file, attribute)
111+
self.read_wrap_entries(setting_file, attribute, user_attribute)
112112

113113
def inline(self, edit, sel):
114114
"""Inline wrap."""
@@ -230,13 +230,13 @@ def select(self, edit):
230230
elif len(final_sel):
231231
self.view.sel().add(final_sel[0])
232232

233-
def read_wrap_entries(self, setting_file, attribute):
233+
def read_wrap_entries(self, setting_file, attribute, user_attribute):
234234
"""Read wrap entries from the settings file."""
235235

236236
settings = sublime.load_settings(setting_file)
237237
syntax = self.view.settings().get('syntax')
238238
language = splitext(basename(syntax))[0].lower() if syntax is not None else "plain text"
239-
wrapping = settings.get(attribute, [])
239+
wrapping = settings.get(attribute, []) + settings.get(user_attribute, [])
240240
for i in wrapping:
241241
if not exclude_entry(i["enabled"], i["language_filter"], i["language_list"], language):
242242
for j in i.get("entries", []):
@@ -302,7 +302,7 @@ def run(self, edit):
302302
self._brackets = []
303303
self._insert = []
304304
self._style = []
305-
self.read_wrap_entries("bh_wrapping.sublime-settings", "wrapping")
305+
self.read_wrap_entries("bh_wrapping.sublime-settings", "wrapping", "user_wrapping")
306306

307307
if len(self._menu):
308308
self.view.window().show_quick_panel(

bh_wrapping.sublime-settings

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@
7373
{"name": "CSS: @group", "brackets": ["/* @group ${BH_SEL:NAME} */", "/* @end */"], "insert_style": ["block"]}
7474
]
7575
}
76-
]
76+
],
77+
// user_swapping will be appended to the tail of swapping
78+
// If you have custom rules that you don't want to commit to
79+
// the official list, and do not need to be inserted before
80+
// one of the official definitions, this is a good place to
81+
// put yours rules and keep in sync with the defaults.
82+
"user_swapping": [],
7783
}

docs/src/markdown/customize.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ Parameters | Description
675675

676676
### Bracket Rule Management
677677

678-
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.
678+
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.
679679

680680
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":
681681

0 commit comments

Comments
 (0)