Save the edit when running a Sublime Text 3 plugin

只愿长相守 提交于 2019-12-04 19:17:30

问题


For understanding what I'm trying to achieve : printing delayed text in another view...

I'm trying to make this sublime text 3 plugin run properly I want to call multiple method of my class using the edit passed in parameter of my run method as so :

# sample code, nothing real
class MyCommandClass(sublime_plugin.TextCommand):
    myEdit = None
    def run(self, edit):
        self.myEdit = edit
        # stuff
        self.myMethod()

    def myMethod(self):
        # use self.myEdit ...

And I try to use it later on another method, but when I execute the plugin I get this error :
ValueError: Edit objects may not be used after the TextCommand's run method has returned

For what I understand, all use of the edit object must be before the run command has returned. And as I'm playing with set_timeout, it might not be the case... So what can I do ?

Thanks in advance.


回答1:


Solution found, to pass an argument to another view and use the edit :

class MainCommand(sublime_plugin.WindowCommand):
    def run(self):
        newFile = self.window.new_file()
        newFile.run_command("second",{ "arg" : "this is an argument"});

class SecondCommand(sublime_plugin.TextCommand):
    def run(self, edit, argument):
        # do stuff with argument


来源:https://stackoverflow.com/questions/20466014/save-the-edit-when-running-a-sublime-text-3-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!