Create a gist now

Instantly share code, notes, and snippets.

Sublime : 2 Columns Layout Management
[
{ "keys" : [ "alt+1" ], "command" : "focus_group", "args" : { "group" : 0 } },
{ "keys" : [ "alt+2" ], "command" : "focus_group", "args" : { "group" : 1 } },
{ // workspace left
"keys" : [ "ctrl+alt+super+left" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.80, 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" }
]
}
},
{ // fetch from the right
"keys" : [ "ctrl+alt+left" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{ // give visual feedback due to change of focus, if coming from the right
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.80, 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" },
{ "command" : "move_to_group", "args" : { "group" : 0 }, "context" : "window" },
{ "command" : "focus_group", "args" : { "group" : 0 }, "context" : "window" }
]
}
},
{ // put to the right
"keys" : [ "ctrl+alt+right" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{ // give visual feedback due to change of focus, if coming from the right
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.80, 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" },
{ "command" : "move_to_group", "args" : { "group" : 1 }, "context" : "window" },
{ "command" : "focus_group", "args" : { "group" : 0 }, "context" : "window" }
]
}
},
{ // workspace right
"keys" : [ "ctrl+alt+super+right" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.20, 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" }
]
}
},
{ // fetch from the left
"keys" : [ "alt+super+right" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{ // give visual feedback due to change of focus, if coming from the left
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.20, 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" },
{ "command" : "move_to_group", "args" : { "group" : 1 }, "context" : "window" },
{ "command" : "focus_group", "args" : { "group" : 1 }, "context" : "window" }
]
}
},
{ // put to the left
"keys" : [ "alt+super+left" ],
"command" : "run_multiple_commands",
"args" : {
"commands" : [
{ // give visual feedback due to change of focus, if coming from the left
"command" : "set_layout",
"args" : {
"cols" : [ 0.0, 0.20, 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" },
{ "command" : "move_to_group", "args" : { "group" : 0 }, "context" : "window" },
{ "command" : "focus_group", "args" : { "group" : 1 }, "context" : "window" }
]
}
}
]
# 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'])
# uncomment the next line, if you want to add a delay to the execution
# sublime.set_timeout( lambda: context.run_command(command['command']), 2000 )
else:
context.run_command(command['command'], args)
# uncomment the next line, if you want to add a delay to the execution
# sublime.set_timeout( lambda: context.run_command(command['command'], args), 2000 )
def run(self, edit, commands = None):
if commands is None:
return # not an error
for command in commands:
self.exec_command(command)
@StefanoRausch

The run_multiple_commands.py has been developed by Nilium - see http://www.sublimetext.com/forum/viewtopic.php?f=5&t=8677 for a discussion.

@felipetiza

Works on ST3, thanks for sharing mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment