Skip to content

Commit d1d70dd

Browse files
committed
Add Python-specific bindings for quotes and curly braces.
1 parent 5f8eef9 commit d1d70dd

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
// Auto-pair quotes
3+
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
4+
[
5+
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
6+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
7+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
8+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(?:[bfruBFRU]|[^'[:alnum:]_])$", "match_all": true },
9+
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double - punctuation.definition.string.end", "match_all": true },
10+
{ "key": "eol_selector", "operator": "equal", "operand": "source.python", "match_all": true }
11+
]
12+
},
13+
// Auto-pair single quotes
14+
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "context":
15+
[
16+
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
17+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
18+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
19+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(?:[bfruBFRU]|[^'[:alnum:]_])$", "match_all": true },
20+
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true },
21+
{ "key": "eol_selector", "operator": "equal", "operand": "source.python", "match_all": true }
22+
]
23+
},
24+
// Auto-pair curly brackets
25+
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
26+
[
27+
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
28+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
29+
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^\\{", "match_all": true },
30+
{ "key": "selector", "operator": "equal", "operand": "meta.fstring.python", "match_all": true },
31+
{ "key": "selector", "operator": "equal", "operand": "string.quoted", "match_all": true }
32+
]
33+
},
34+
// Replace a '{|}' with '{{|' when typing within fstring
35+
{ "keys": ["{"], "command": "run_macro_file",
36+
"args": {"name": "Packages/MagicPython/snippets/sublime/fstring_brace.sublime-macro"},
37+
"context":
38+
[
39+
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
40+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
41+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
42+
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true },
43+
{ "key": "selector", "operator": "equal", "operand": "meta.fstring.python", "match_all": true },
44+
{ "key": "selector", "operator": "equal", "operand": "constant.character.format.placeholder.other", "match_all": true }
45+
]
46+
},
47+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"command": "right_delete",
4+
"args": null
5+
},
6+
{
7+
"command": "insert",
8+
"args": {"characters": "{"}
9+
}
10+
]

0 commit comments

Comments
 (0)