Last active
December 11, 2015 23:58
-
-
Save jamiehs/4679868 to your computer and use it in GitHub Desktop.
Plugin for SublimeText2 that allows multiple keyboard commands from one shortcut. Tools > New Plugin
Select all, then paste this plugin in. Save it in your user folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example Usage | |
[ | |
{ "keys": ["ctrl+w"], | |
"command": "run_multiple_commands", | |
"args": { | |
"commands": [ | |
{"command": "find_under_expand", "context": "window"}, | |
{"command": "slurp_find_string", "context": "window"}, | |
{"command": "show_panel", "args": {"panel": "find"}, "context": "window"} | |
]}} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run_multiple_commands.py | |
import sublime, sublime_plugin | |
# Takes an array of commands (same as those you'd provide to a key binding) with | |
# an optional context (defaults to view commands) & runs each command in order. | |
# Valid contexts are 'text', 'window', and 'app' for running a TextCommand, | |
# WindowCommands, or ApplicationCommand respectively. | |
class RunMultipleCommandsCommand(sublime_plugin.TextCommand): | |
def exec_command(self, command): | |
if not 'command' in command: | |
raise Exception('No command name provided.') | |
args = None | |
if 'args' in command: | |
args = command['args'] | |
# default context is the view since it's easiest to get the other contexts | |
# from the view | |
context = self.view | |
if 'context' in command: | |
context_name = command['context'] | |
if context_name == 'window': | |
context = context.window() | |
elif context_name == 'app': | |
context = sublime | |
elif context_name == 'text': | |
pass | |
else: | |
raise Exception('Invalid command context "'+context_name+'".') | |
# skip args if not needed | |
if args is None: | |
context.run_command(command['command']) | |
else: | |
context.run_command(command['command'], args) | |
def run(self, edit, commands = None): | |
if commands is None: | |
return # not an error | |
for command in commands: | |
self.exec_command(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment