Keymap commands
class KeymapCommand(Command):
def is_context(self):
return False
def run(self):
pass
Usage
*.sublime-keymap
{
"keys": ["tab"],
"command": "command_name"
}
class CommandName(KeymapCommand):
def is_context(self):
# ...
def run(self):
# ...
Motivation
Removes plugin boilerplate, duplication and allows plugins to circumvents possible performance issues.
For example, one way to currently achieve something similar to this api, but impacts performace and introduces duplication and more complicated code, is to use an event listener.
class FinishCompletionContext(sublime_plugin.EventListener):
def on_query_context(self, view, key, operator, operand, match_all):
if key == 'finish_completion':
if is_finish_completion_context(view):
return True
return None
The above can then be used as keymap context.
{
"keys": [")"],
"command": "finish_completion",
"context": [
{ "key": "finish_completion", "operator": "equal", "operand": true, "match_all": true }
]
}
The event listener in this case only needs to be fired for the )
keymap.