├── README.md └── VoiceCode.py /README.md: -------------------------------------------------------------------------------- 1 | # VoiceCode / Sublime Text (2|3) Integration Package 2 | 3 | This is a Sublime Text plugin that lets [VoiceCode](http://voicecode.io) control [Sublime Text](https://www.sublimetext.com) 4 | 5 | This integration is needed because many VoiceCode voice commands are more sophisticated than simply pressing keys or clicking the mouse. For example, a command that *selects the next curly brace*, or a command that *extends the current selection(s) forward until the next comma*, etc. 6 | 7 | ## Setup 8 | 9 | First make sure the commandline utility for Sublime Text is installed and working https://www.sublimetext.com/docs/3/osx_command_line.html 10 | 11 | ## Adding your own commands 12 | 13 | If you want to add new commands that are not already included in this package, just add something similar to the following in a user extension file for Sublime Text. 14 | 15 | ```python 16 | import sublime, sublime_plugin 17 | 18 | class SelectPreviousWordCommand(sublime_plugin.TextCommand): 19 | def run(self, edit): 20 | pos = self.view.sel()[0].begin() 21 | all_previous = [r for r in self.view.find_all('\w+') if r.begin() < pos] 22 | if all_previous: 23 | region = all_previous[-1] # return nearest 24 | if region: 25 | self.view.sel().clear() 26 | self.view.sel().add(region) 27 | ``` 28 | 29 | Then, in your VoiceCode user commands, you can call this Sublime Text command as follows: 30 | 31 | ```coffeescript 32 | @sublime().do('select_previous_word') 33 | ``` 34 | 35 | or if you need to pass options/arguments to a Sublime command, add them as the second parameter like: 36 | 37 | ```coffeescript 38 | @sublime().do('some_command', {foo: "bar", baz: 3.2}) 39 | ``` 40 | ### Triggering existing Sublime Text commands 41 | 42 | Sublime has a lot of builtin commands. To trigger them from VoiceCode simply do something like: 43 | 44 | ```coffeescript 45 | @sublime().do('goto_line', {line: 10}) 46 | ``` 47 | 48 | Checkout [this page](http://docs.sublimetext.info/en/latest/reference/commands.html#discovering-commands) for more info about Sublime commands. 49 | -------------------------------------------------------------------------------- /VoiceCode.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin 2 | 3 | class SelectNextNumberCommand(sublime_plugin.TextCommand): 4 | def run(self, edit): 5 | pos = self.view.sel()[0].end() 6 | region = self.view.find('(?:\d*\.)?\d+', pos) 7 | 8 | if region.a == -1: 9 | region.a = pos 10 | region.b = pos 11 | 12 | self.view.sel().clear() 13 | self.view.sel().add(region) 14 | 15 | class SelectNextWordCommand(sublime_plugin.TextCommand): 16 | def run(self, edit): 17 | pos = self.view.sel()[0].end() 18 | region = self.view.find('\w+', pos) 19 | 20 | if region.a == -1: 21 | region.a = pos 22 | region.b = pos 23 | 24 | self.view.sel().clear() 25 | self.view.sel().add(region) 26 | 27 | class SelectPreviousWordCommand(sublime_plugin.TextCommand): 28 | def run(self, edit): 29 | pos = self.view.sel()[0].begin() 30 | all_previous = [r for r in self.view.find_all('\w+') if r.begin() < pos] 31 | if all_previous: 32 | region = all_previous[-1] # return nearest 33 | if region: 34 | self.view.sel().clear() 35 | self.view.sel().add(region) 36 | 37 | 38 | 39 | --------------------------------------------------------------------------------