简体   繁体   English

运行Sublime Text 3插件时保存编辑

[英]Save the edit when running a Sublime Text 3 plugin

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 : 我正在尝试使这个崇高的文本3插件正常运行我想使用我的run方法的参数传递的编辑调用我的类的多个方法,如下所示:

# 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. 据我所知,编辑对象的所有使用必须在返回run命令之前。 And as I'm playing with set_timeout , it might not be the case... So what can I do ? 当我正在玩set_timeout ,情况可能并非如此......那么我该怎么办?

Thanks in advance. 提前致谢。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM