Skip to content

Instantly share code, notes, and snippets.

@pyatil
Forked from nilium/key-bindings.json
Created February 25, 2014 09:30
Show Gist options
  • Save pyatil/9205706 to your computer and use it in GitHub Desktop.
Save pyatil/9205706 to your computer and use it in GitHub Desktop.

Revisions

  1. Noel Cower created this gist Aug 11, 2012.
    12 changes: 12 additions & 0 deletions key-bindings.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    [
    {
    "keys": ["ctrl+w"],
    "command": "run_multiple",
    "args": {
    "commands": [
    {"command": "find_under_expand", "args": null, "context": "window"},
    {"command": "show_panel", "args": {"panel": "find"}, "context": "window"}
    ]
    }
    }
    ]
    40 changes: 40 additions & 0 deletions run_multiple.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    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 RunMultipleCommand(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)