繁体   English   中英

创建sublime文本插件支持ST2和ST3

[英]Create sublime text plugin support both ST2 and ST3

我为Sublime Text 2制作了几个插件,但是当Sublime Text 3出来时,它有一个新的Python引擎,我的插件停止工作。 我设法通过逐个调试所有问题来修复它们,但现在我有两个版本。 原始版本从Package Manager顺利安装,但新版本只能从我从git检出的代码分支中安装。

我应该如何正确管理sublime文本的插件以支持多个版本?

有没有关于如何有效地做到这一点的博客文章?

您可以为Sublime Text的不同构建管理两个不同的代码分支。 如果你看看第200行及其后的example-repository.json ,你会看到这个例子:

// If your package is only compatible with specific builds of
// Sublime Text, this will cause the package to be hidden from
// users with incompatible versions.
{
    "details": "https://github.com/wbond/sublime_alignment",
    "releases": [
        {
            // This branch (default: "master") is for Sublime Text 2.
            // Remember: The sublime_text key is required!
            "sublime_text": "<3000",
            "details": "https://github.com/wbond/sublime_alignment"
        }
        {
            // This branch ("st3") is for Sublime Text 3 (and above).
            // You can specify as many releases as you want.
            "sublime_text": ">=3000",
            "details": "https://github.com/wbond/sublime_alignment/tree/st3"
        }
    ]
},

这样,如果您为不同版本的ST或甚至ST3的不同版本提供不同的代码库,如果您依赖于仅在某个版本中实现的某些API更改,最终用户将无缝地获取您的版本你想要他们的插件。

这可能是不可能的,这取决于您如何使用API​​,但从长远来看,最简单的方法是在ST2和ST3之间协调您的代码。 如果需要使用某些高级功能,则可以始终使用此类构造:

if sublime.version() >= 3000:
    do_advanced_stuff()
else:
    do_st2_stuff()

分解代码并优雅地失败,在某些情况下,在ST2下运行的某些插件可能不具备使用ST3时所具有的功能。

暂无
暂无

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

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