Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user_swapping and user_wrapping #522

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 10 additions & 4 deletions bh_swapping.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]}
]
},
{
Expand All @@ -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
16 changes: 11 additions & 5 deletions bh_wrapping.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]}
]
},
{
Expand Down Expand Up @@ -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": []
}
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