【问题标题】:Save the edit when running a Sublime Text 3 plugin运行 Sublime Text 3 插件时保存编辑
【发布时间】:2013-12-26 06:57:59
【问题描述】:

为了理解我想要实现的目标:在另一个视图中打印延迟文本...

我正在尝试使这个 sublime text 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 ...

我稍后尝试在另一种方法上使用它,但是当我执行插件时出现此错误:
ValueError: Edit objects may not be used after the TextCommand's run method has returned

据我了解,编辑对象的所有使用都必须在运行命令返回之前。而当我在玩set_timeout 时,情况可能并非如此......那我该怎么办?

提前致谢。

【问题讨论】:

    标签: python sublimetext3 sublime-text-plugin


    【解决方案1】:

    找到解决方案,将参数传递给另一个视图并使用编辑:

    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
    

    【讨论】:

    • 我猜你的意思是sublime.set_timeout(lambda: newFile.run_command(...), 1000)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 2014-02-13
    • 2016-06-18
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多