Skip to content

Commit dcb0ca8

Browse files
Add option to add context-specific bracket types
1 parent f3d3f46 commit dcb0ca8

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ The Wrap plugin can be customized to your requirements.
2727

2828
### 🔧 Preferences
2929

30-
The type of brackets used by `Wrap` can be customized via the command `Preferences: Wrap`.
30+
The types of brackets used by `Wrap` can be customized via the command `Preferences: Wrap`.
3131

32-
Simply change the `bracket_type` to your preference.
32+
Change the default bracket type with the `bracket_type` setting.
33+
34+
Change context-specific bracket types with the `contexts` setting.
3335

3436
### ⌨ Keybindings
3537

Wrap.sublime-settings

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2-
// Type of brackets to use (examples: (), [], {})
3-
"bracket_type": "()"
2+
// Default bracket type (examples: (), [], {})
3+
"bracket_type": "()",
4+
5+
// Context-specific bracket types (overrides default)
6+
"contexts": [
7+
{
8+
"name": "LaTeX",
9+
"scope": "text.tex.latex",
10+
"extensions": ["tex"],
11+
"bracket_type": "{}"
12+
}
13+
]
414
}

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"install": "messages/install.txt"
2+
"install": "messages/install.txt",
3+
"1.1.0": "messages/1.1.0.txt"
34
}

messages/1.1.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
v1.1.0
2+
3+
There is now the option to add special contexts where overriding bracket types should be used. Use `Preferences: Wrap` in the command palette to open the settings file and do so.

wrap.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
class WrapCommand(sublime_plugin.TextCommand):
66
def run(self, edit):
77
settings = sublime.load_settings("Wrap.sublime-settings")
8-
a, b = settings.get("bracket_type", "()")
8+
extension = self.view.file_name().split(".")[-1]
9+
10+
# Determine bracket type
11+
for c in settings.get("contexts"):
12+
if self.view.match_selector(self.view.sel()[0].begin(), c.get("scope")) or extension in c.get("extensions"):
13+
a, b = c.get("bracket_type", "()")
14+
break
15+
else:
16+
a, b = settings.get("bracket_type", "()")
917

1018
region = self.view.sel()[0]
1119

0 commit comments

Comments
 (0)