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

标签 python sublimetext3 sublime-text-plugin

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

我正在尝试使这个 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:在 TextCommand 的运行方法返回后可能无法使用编辑对象

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

提前致谢。

最佳答案

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

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

关于python - 运行 Sublime Text 3 插件时保存编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20466014/

相关文章:

sublimetext3 - 在聚焦其他组打开文件后如何将焦点恢复到快速面板?

angularjs - Sublimetext 3 和 AngularJS - 语法高亮 (HTML)

editor - 如何在Sublime Text中更改选项卡名称?

python - 在 Windows 10 中的任务计划程序上计划 .py 文件

python - Python 中是否可以换行注释?

python - 返回数据帧作为对 azure 函数的响应

sublimetext2 - Sublime Text 水平滚动键盘

python - 使用 rpy2 导入并使用 R 'heavy' 包

autocomplete - 修改 Sublime Text 3 默认 <script> 标签

sublimetext3 - 如何在 Sublime Text 3 中通过 "Ctrl+Click"访问一个类