Skip to content

Commit 021931b

Browse files
committed
sublime: Replace the f-string macro with a Python plugin.
Macro approach is less reliable because the path to the macro file has to be hardcoded. If MP is installed into a non-standard dir, the {} completion wouldn't work properly.
1 parent 3126d02 commit 021931b

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

Diff for: settings/sublime/Default.sublime-keymap

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
{ "key": "selector", "operator": "equal", "operand": "string.quoted", "match_all": true }
3232
]
3333
},
34-
// Replace a '{|}' with '{{|' when typing within fstring
35-
{ "keys": ["{"], "command": "run_macro_file",
36-
"args": {"file": "Packages/MagicPython/settings/sublime/fstring_brace.sublime-macro"},
34+
// Replace a '{|}' with '{{|' when typing within f-string
35+
{ "keys": ["{"], "command": "fstringbrace",
3736
"context":
3837
[
3938
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },

Diff for: settings/sublime/fstring_brace.sublime-macro

-10
This file was deleted.

Diff for: sublime.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""A plugin for Sublime Text to enhance f-string editing experience.
2+
3+
Specifically, this plugin simplifies typing of escaped curly braces
4+
in an f-string:
5+
{|}, where | is for cursir, gets replaced with
6+
{{|, when '{' is typed again.
7+
"""
8+
9+
10+
import sublime
11+
import sublime_plugin
12+
13+
14+
class FstringbraceCommand(sublime_plugin.WindowCommand):
15+
def run(self):
16+
view = self.window.active_view()
17+
view.run_command('right_delete')
18+
view.run_command('insert', {'characters': '{'})

0 commit comments

Comments
 (0)