我正在尝试为SublimeText3开发一些插件。
该插件应该对文本的每次修改都起作用,因此请查看 api
http://www.sublimetext.com/docs/3/api_reference.html
on_modified_async(view)
是我猜想使用的那个。
所以代码是这样的:
#!/usr/bin/env python
import sublime, sublime_plugin, socket
class testCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World1!")
self.view.insert(edit, 0, "Hello, World2!")
def on_modified_async(self, view):
self.view.insert(edit, 0, "Hello, World3!")
此代码适用于 Hello, world 1&2,但永远不会触发 3。
我对 SublimeText 插件和 python3.3 开发都很陌生。我想念什么?谢谢你。// 编辑
MESSAGE = self.view.substr(0,50)
TypeError: substr() takes 2 positional arguments but 3 were given
看起来我给出了 2 个位置参数,而不是 3 个。
我有一个错误:AttributeError:'MyEventListener'对象没有属性'view'......我的代码有什么问题(已编辑)
import sublime, sublime_plugin, socket
class testCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World1!")
class MyEventListener(sublime_plugin.EventListener):
def on_modified_async(self,view):
self.view.insert(edit, 0, "Hello, World2!")
--
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 279, in on_modified_async
callback.on_modified_async(v)
File "/Users/ken/Library/Application Support/Sublime Text 3/Packages/test/test.py", line 11, in on_modified_async
self.view.insert(edit, 0, "Hello, World2!")
AttributeError: 'MyEventListener' object has no attribute 'view'
这是工作代码:
import sublime, sublime_plugin, socket
class MarkdownLiveCommand(sublime_plugin.TextCommand):
def run(self, edit):
tcp(self.view)
class MyEventListener1(sublime_plugin.EventListener):
def on_modified_async(self, view):
tcp(view)
def tcp(view):
#do the job