sublime text 插件开发
程序员文章站
2022-07-05 10:19:06
...
(一)新建插件
1.点击打开扩展包目录
2.新建Test目录
3.创建新的插件文件并保存到Test目录
4.修改示例代码为
import sublime
import sublime_plugin
class testCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("testCommand")
5.快捷键 ctrl+~ 唤出控制台,输入view.run_command('test'),回车执行,看到上面成功输出
6.新建快捷键配置表,f5即可执行test命令
传入参数
{ "keys": ["f5"], "command": "test", "args": {"test_param_1":"11111"} }
import sublime
import sublime_plugin
class testCommand(sublime_plugin.TextCommand):
def run(self, edit, test_param_1):
print("testCommand", test_param_1)
f5执行后输出
参考:
How to Create a Sublime Text Plugin
(二)示例
1.鼠标悬停,提取字符
import sublime
import sublime_plugin
class testOnHover(sublime_plugin.EventListener):
def on_hover(self, view, point, hover_zone):
#print("on_hover", view, point, hover_zone)
if (hover_zone != sublime.HOVER_TEXT):
return
hovered_word = view.substr(view.word(point)).strip()
print("hovered_line_text", hovered_word)