1、通过Tools -> New Plugin...来打开一个初始化的插件编辑文件,它将有如下的内容:
import sublime, sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
2、通过Preferences -> Browse Packages...打开Packages文件夹,在该文件夹下建立个子文件夹,名字为你想开发的插件名字,如:KeymapManager。回到插件开发的初始化编辑器页面,通过ctrl+s (Windows/Linux) orcmd+s (OS X)保存这个文件,并放到你建立的子文件夹下,文件名如:KeymapManager.py
3、通过ctrl+`快捷键打开SublimeText的控制台,执行如下的命令:
view.run_command(‘example‘)如果你在当前文件最前面看到插入了Hello, Word!,那表明插件执行成功了。
4、ExampleCommand名字改为你想要的插件名字,如: KeymapmanagerCommand,然后就可以开发该插件对应的功能了。
5、通过官方的API文档查找你需要的接口,文档见:http://www.sublimetext.com/docs/2/api_reference.html
import sublime, sublime_plugin import threading import time i=0 class timer(threading.Thread): #The timer class is derived from the class threading.Thread def __init__(self, num, interval): threading.Thread.__init__(self) self.thread_num = num self.interval = interval self.thread_stop = False def run(self): #Overwrite run() method, put what you want the thread do here global i while not self.thread_stop: sublime.set_timeout(write_time,1) i+=1 time.sleep(self.interval) def pause(self): self.thread_stop = True def zero(self): global i i=0 thread1 = timer(1, 1) class gtimerCommand(sublime_plugin.TextCommand): def run(self, edit): global thread1 thread=timer(1,1) if thread1.isAlive(): live=True else: thread.start() thread1=thread class gtimerpauseCommand(sublime_plugin.TextCommand): def run(self, edit): global thread1 thread1.pause() class gtimerzeroCommand(sublime_plugin.TextCommand): def run(self, edit): global thread1 thread1.zero() def write_time(): sublime.status_message(time_manage(i)) def time_manage(time_number): time_str=‘time:‘+str(time_number/60)+‘min ‘+str(time_number%60)+‘s‘ return time_str
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/
原文地址:http://blog.csdn.net/buptgshengod/article/details/40001171