0
我有一个崇高的插件,但我想,当用户键入一个}
或;
如何在用户输入时运行一个sublime plugin命令;或}
我试图处理它在on_modified
事件做一些事情,但我不能完全得到它的工作。
这是最好的方法吗?
我有一个崇高的插件,但我想,当用户键入一个}
或;
如何在用户输入时运行一个sublime plugin命令;或}
我试图处理它在on_modified
事件做一些事情,但我不能完全得到它的工作。
这是最好的方法吗?
添加与您的插件捆绑在一起的新键绑定。作为一个例子,这里是触发大括号的自动配对的默认键绑定:
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|$)", "match_all": true }
]
},
{ "keys": ["{"], "command": "wrap_block", "args": {"begin": "{", "end": "}"}, "context":
[
{ "key": "indented_block", "match_all": true },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
]
},
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{${0:$SELECTION}}"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
},
注意,通过使用单个字符作为键绑定,你拦截按键,它不会在显示缓冲。如果你想把字符发送到缓冲区,你需要把它放在那里作为你的命令的一部分。
您可以在示例中看到。这两个insert_snippet
命令包裹的任何参数与大括号:"contents": "{$0}"
和wrap_block
命令发送大括号的开始和结束ARGS:"args": {"begin": "{", "end": "}"}
我试过了,它执行我的命令,但'}'心不是在编辑器中 – Jon 2015-02-09 20:57:28
@乔恩我已经添加了一些额外的解释 – 2015-02-09 21:10:00