├── README.md ├── keymap-example.json └── run_multiple_commands.py /README.md: -------------------------------------------------------------------------------- 1 | # Sublime Text Multi Commands 2 | 3 | A simple python script that enable users to easily execute multiple commands in Sublime Text 3. The original author is **Nilium**, who shared the original python code [here](https://www.sublimetext.com/forum/viewtopic.php?f=5&t=8677). 4 | 5 | I made a very tiny change to the code so that it can work with packages like [sublime-evernote](https://github.com/bordaigorl/sublime-evernote). 6 | 7 | 8 | ## Install 9 | 10 | Download and put **run_multiple_commands.py** in your `/Packages/User/` directory. 11 | 12 | You can find the directory through `Preferences -> Browse Packages` in Sublime Text. Or depending on your OS, you can allocated it at: 13 | 14 | OSX 15 | 16 | ~Library/Application Support/Sublime Text 3/Packages 17 | 18 | Windows 19 | 20 | C:\Users\epti-215\AppData\Roaming\Sublime Text 3\Packages 21 | 22 | Linux 23 | 24 | ~/.config/sublime-text-3/Packages/ 25 | 26 | ## Usage 27 | 28 | Open your `sublime-keymap` file from `Preferences -> Key Bindings` in Sublime Text. Add multiple commands like the following examples. 29 | 30 | ### Save file & Update to evernote 31 | 32 | In this example, when the user click "super+s", command *save* and command *save_evernote_note* will be executed. 33 | 34 | ```json 35 | { 36 | "keys": [ 37 | "super+s" 38 | ], 39 | "command": "run_multiple_commands", 40 | "args": { 41 | "commands": [ 42 | { 43 | "command": "save" 44 | }, 45 | { 46 | "command": "save_evernote_note", 47 | "context": [ 48 | { 49 | "key": "evernote_note" 50 | } 51 | ] 52 | } 53 | ] 54 | } 55 | } 56 | ``` 57 | 58 | ### Another example: 59 | 60 | This is the example provided by **Nilium**. 61 | 62 | ```json 63 | { 64 | "keys": [ 65 | "ctrl+w" 66 | ], 67 | "command": "run_multiple_commands", 68 | "args": { 69 | "commands": [ 70 | { 71 | "command": "find_under_expand", 72 | "context": "window" 73 | }, 74 | { 75 | "command": "show_panel", 76 | "args": { 77 | "panel": "find" 78 | }, 79 | "context": "window" 80 | } 81 | ] 82 | } 83 | } 84 | ``` 85 | 86 | ## Credit 87 | 88 | For Sublime Text Multi Commands, credit gose to its original author, **Nilium**. 89 | For [Sublime Evernote](https://github.com/bordaigorl/sublime-evernote), credit goes to its contributors. -------------------------------------------------------------------------------- /keymap-example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": [ 4 | "super+s" 5 | ], 6 | "command": "run_multiple_commands", 7 | "args": { 8 | "commands": [ 9 | { 10 | "command": "save" 11 | }, 12 | { 13 | "command": "save_evernote_note", 14 | "context": [ 15 | { 16 | "key": "evernote_note" 17 | } 18 | ] 19 | } 20 | ] 21 | } 22 | } 23 | ] -------------------------------------------------------------------------------- /run_multiple_commands.py: -------------------------------------------------------------------------------- 1 | # run_multiple_commands.py 2 | 3 | # Author: Nilium 4 | # Purpose: To easily run multiple commands in Sublime Text. 5 | # Full discussion: https://www.sublimetext.com/forum/viewtopic.php?f=5&t=8677 6 | 7 | # Usage: Sublime Text -> Preferences -> Key Bindings - User, Edit your keymap file 8 | # [ 9 | # { "keys": ["ctrl+w"], 10 | # "command": "run_multiple_commands", 11 | # "args": { 12 | # "commands": [ 13 | # {"command": "find_under_expand", "context": "window"}, 14 | # {"command": "slurp_find_string", "context": "window"}, 15 | # {"command": "show_panel", "args": {"panel": "find"}, "context": "window"} 16 | # ]}} 17 | # ] 18 | 19 | # Another Example: To save file to disk and update file to Evernote 20 | # This example requires [sublime-evernote](https://github.com/bordaigorl/sublime-evernote) 21 | # { 22 | # "keys": [ 23 | # "super+s" 24 | # ], 25 | # "command": "run_multiple_commands", 26 | # "args": { 27 | # "commands": [ 28 | # { 29 | # "command": "save", 30 | # }, 31 | # { 32 | # "command": "save_evernote_note", 33 | # "context": [ 34 | # { 35 | # "key": "evernote_note" 36 | # } 37 | # ] 38 | # } 39 | # ] 40 | # } 41 | # } 42 | 43 | import sublime, sublime_plugin 44 | 45 | # Takes an array of commands (same as those you'd provide to a key binding) with 46 | # an optional context (defaults to view commands) & runs each command in order. 47 | # Valid contexts are 'text', 'window', and 'app' for running a TextCommand, 48 | # WindowCommands, or ApplicationCommand respectively. 49 | class RunMultipleCommandsCommand(sublime_plugin.TextCommand): 50 | def exec_command(self, command): 51 | if not 'command' in command: 52 | raise Exception('No command name provided.') 53 | 54 | args = None 55 | if 'args' in command: 56 | args = command['args'] 57 | 58 | # default context is the view since it's easiest to get the other contexts 59 | # from the view 60 | context = self.view 61 | if 'context' in command: 62 | context_name = command['context'] 63 | if context_name == 'window': 64 | context = context.window() 65 | elif context_name == 'app': 66 | context = sublime 67 | elif context_name == 'text': 68 | pass 69 | else: 70 | # Workaround for sublime-evernote package, modified by Chien Chun 71 | pass 72 | # values = ','.join(str(v) for v in context_name) 73 | # raise Exception('Invalid command context "'+values+'".') 74 | 75 | 76 | # skip args if not needed 77 | if args is None: 78 | context.run_command(command['command']) 79 | else: 80 | context.run_command(command['command'], args) 81 | 82 | def run(self, edit, commands = None): 83 | if commands is None: 84 | return # not an error 85 | for command in commands: 86 | self.exec_command(command) --------------------------------------------------------------------------------