Skip to content

Commit

Permalink
Added user_swapping and user_wrapping overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolfsonkin committed Jun 7, 2019
1 parent ec4a016 commit a902788
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bh_swapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion bh_swapping.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
}
10 changes: 5 additions & 5 deletions bh_wrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ 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
self._menu = []
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."""
Expand Down Expand Up @@ -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", []):
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion bh_wrapping.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
}
2 changes: 1 addition & 1 deletion docs/src/markdown/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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":

Expand Down

0 comments on commit a902788

Please sign in to comment.