【问题标题】:Sublime Text 3: How do I make a keybind to enable and disable Anaconda linting?Sublime Text 3:如何进行键绑定以启用和禁用 Anaconda linting?
【发布时间】:2021-01-24 17:37:40
【问题描述】:

我希望能够使用热键来启用/禁用 anaconda linting。每次我必须使用它时都必须打开设置真的很不方便。我是 Sublime Text 的新手,但从我在 Keybindings 中看到的内容来看,您可以使用 args 传递一个变量。例如:

[{"keys": ["ctrl+q"], "command": "toggle_comment", "args": {"block": false}}]

所以,我在想,也许有一个命令可以更改包“设置 - 用户”并传递一个 var 以将 [“anaconda_linting”: false,] 设置为 true 或 false?

【问题讨论】:

    标签: python sublimetext3 sublime-anaconda


    【解决方案1】:

    您可以使用自定义插件和键绑定来做到这一点。选择Tools → Developer → New Plugin…并将打开的文件内容设置为:

    import sublime
    import sublime_plugin
    
    
    class ToggleAnacondaLintingCommand(sublime_plugin.ApplicationCommand):
        def run(self):
            s = sublime.load_settings("Anaconda.sublime-settings")
            current = s.get("anaconda_linting")
            new = not current
            s.set("anaconda_linting", new)
            sublime.save_settings("Anaconda.sublime-settings")
            sublime.active_window().run_command('save')
    

    点击 CtrlS 保存,您的 Packages/User 文件夹应该会打开。将文件另存为toggle_anaconda_linting.py

    现在,打开您的键绑定并在 [ ] 字符之间添加以下内容(选择您想要的任何快捷方式):

    {"keys": ["ctrl+alt+shift+l"], "command": "toggle_anaconda_linting"},
    

    现在,只要您点击快捷方式,所有文件都会切换"anaconda_linting"

    【讨论】:

    • 感谢您的回答!我真的很感激它的工作。虽然有两件事要注意。最初它不起作用,所以我在意识到它没有被使用后删除了“编辑”变量。其次,仅当您“保存”文件时,linting 才会刷新。您知道要添加什么功能,以便您可以与插件代码一起点击保存吗?
    • @Aeiddius 见我上面的编辑。最后添加self.view.run_command("save") 应该可以解决问题。 edit 是以前版本遗留下来的,我只是在更改子类的父类时忘记删除它。
    • self.viewApplicationCommand 中不可用;你需要像sublime.active_window().run_command('save') 这样的东西。
    • 感谢 MattDMo 和 OdatNurd 的回答和建议。它现在完美运行! :) :)
    猜你喜欢
    • 1970-01-01
    • 2015-01-04
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 2019-04-25
    相关资源
    最近更新 更多