本文介绍了运行 Sublime Text 3 插件时保存编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我正在尝试使这个 sublime text 3 插件正常运行我想使用传入我的 run 方法的参数的编辑来调用我的类的多个方法:

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 ...

我稍后尝试在另一种方法上使用它,但是当我执行插件时出现此错误:
ValueError:TextCommand 的 run 方法返回后可能无法使用 Edit 对象

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

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

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 ?

提前致谢.

推荐答案

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

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

这篇关于运行 Sublime Text 3 插件时保存编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 17:45