sublimetext2 - Can I create my own command in sublime and how to associate python implementation to that command? -



sublimetext2 - Can I create my own command in sublime and how to associate python implementation to that command? -

one more depth former question why doesn’t hotkey configuration sublime text work?. come implementation of sublime command, confusing way hack commands sublime has, exploration in former thread in order find command used open browser, found help of @mattdmo.

then find there 1 file named open_in_browser.py in packages/default folder, guess commands file name of .py files, but in fact cannot find corresponding file named find_pre.py command find_prev, re-create open_in_browser.py open_browsers.py, , add together { "keys": ["ctrl+b"], "command": "open_browsers"} sublime keymap, doesn't work. realized there should place registers sublime commands implementation, if there such mechanism, it? can find it?

tl;dr

create file name in packages/user directory. create class in file mytestcommand run method. create keymap using class name in snake case , without command suffix. utilize named arguments pass command.

full answer

there no need register create custom commands. filename doesn't matter sublime text scans it's directories .py scripts , automatically executes them (registers them).

here illustration script use:

import sublime import sublime_plugin class changeviewcommand(sublime_plugin.windowcommand): def run(self, reverse=false): window = self.window group, view_index = window.get_view_index(window.active_view()) if view_index >= 0: views = window.views_in_group(group) if reverse: if view_index == 0: view_index = len(views) if reverse: new_index = view_index - 1 else: new_index = (view_index + 1) % len(views) window.focus_view(views[new_index])

so - switches next/previous tab in current grouping (the default behavior circles around tab groups).

so save name in packages/user directory.

then must create key bindings in our user keymap file:

{ "keys": ["ctrl+tab"], "command": "change_view" }, { "keys": ["ctrl+shift+tab"], "command": "change_view", "args": {"reverse": true} },

as may see, command snake_case of class name without command suffix. run class's run method named arguments.

does reply question? debugging in case of errors - open st console (default shortcut ctrl + `)

sublimetext2 sublimetext sublime-text-plugin

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -