如何从`sublime console`运行WindowCommand插件

时间:2013-10-30 08:41:51

标签: python plugins sublimetext2 sublimetext sublimetext3

我使用3个命令为sublime text 3创建了插件: 其中2个属于TextCommand类型,其中一个是WindowCommand

import sublime, sublime_plugin

class simple_text_pluginCommand(sublime_plugin.TextCommand):
    def run(self, edit):      
        print("Hello World simple_text_plugin")
class simple_text_plugin2Command(sublime_plugin.TextCommand):
    def run(self, edit):      
        print("Hello World simple_text_plugin2")        
class simple_window_pluginCommand(sublime_plugin.WindowCommand):
    def run(self):      
        print("Hello World simple_window_plugin")  

为什么我只能从sublime command line(ctrl +`)调用文本命令:

>>> view.run_command('simple_text_plugin') 
Hello World simple_text_plugin

>>> view.run_command('simple_text_plugin2') 
Hello World simple_text_plugin2

但无法调用window命令:

>>> view.run_command('simple_window_plugin') 

没有输出。如何从Window运行sublime console类型插件?

1 个答案:

答案 0 :(得分:10)

  • ApplicationCommandsublime.run_command('application_command_name')。在API reference。{/ li>中查看run_command模块的sublime功能
  • WindowCommandwindow.run_command('window_command_name')。查看sublime.Windowrun_command方法。
  • TextCommandview.run_command('text_command_name')。查看sublime.Viewrun_command方法。