A slightly optimized version given that this is my most often used command.
[code]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):
ctx_obj_map = {
‘window’: lambda x: x.window(),
‘app’: lambda x: sublime,
‘text’: lambda x: x,
None: lambda x: x,
}
def exec_command(self, command):
# default context is the view since it's easiest to get the other contexts
# from the view
context = RunMultipleCommandsCommand.ctx_obj_map[command.get('context')](self.view)
# skip args if not needed
if 'args' in command:
self.view.window().run_command(command'command'], command'args'])
else:
self.view.window().run_command(command'command'])
def run(self, edit, commands = None):
print (‘running commands:’, commands)
if commands is None:
return # not an error
for command in commands:
self.exec_command(command)
[/code]