Skip to content

Instantly share code, notes, and snippets.

@polyphonic13
Created January 23, 2013 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polyphonic13/4612818 to your computer and use it in GitHub Desktop.
Save polyphonic13/4612818 to your computer and use it in GitHub Desktop.
column shift bindings
[
{
"keys": ["super+alt+left"],
"command": "run_multiple",
"args":{
"commands":[
{
"command": "set_layout",
"args": {
"cols": [0.0, 0.66, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
},
"context": "window"
},
{
"command": "focus_group",
"args": {
"group": 0
},
"context": "window"
}
]
}
},
{
"keys": ["super+alt+right"],
"command": "run_multiple",
"args":{
"commands":[
{
"command": "set_layout",
"args": {
"cols": [0.0, 0.33, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
},
"context": "window"
},
{
"command": "focus_group",
"args": {
"group": 1
},
"context": "window"
}
]
}
}
]
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment