代码之家  ›  专栏  ›  技术社区  ›  john c. j.

为什么宏不工作?

  •  0
  • john c. j.  · 技术社区  · 7 年前

    以下是宏,由于某些原因,它不起作用:

    [
        { "command": "split_selection_into_lines" },
        { "command": "move_to", args: {"to": "hardeol"} },
        { "command": "move_to", args: {"to": "hardbol", "extend": true} },
    ]
    

    我可以通过插件做同样的事情,但我不喜欢在这里使用它:

    import sublime_plugin
    class SplitIntoLinesReverseCommand(sublime_plugin.TextCommand):
        def run(self, edit):
            self.view.run_command("split_selection_into_lines")
            self.view.run_command("move_to", {"to": "hardeol"})
            self.view.run_command("move_to", {"to": "hardbol", "extend": True})
    

    为什么宏不工作?

    1 回复  |  直到 7 年前
        1
  •  1
  •   OdatNurd    7 年前

    宏不起作用,因为用于定义它的JSON无效 args 密钥需要用双引号括起来,但不是。因此,宏不会加载,因此无法执行。

    如果您的配色方案支持,则将突出显示无效字符,以指示问题所在。

    正确的版本是:

    [
        { "command": "split_selection_into_lines" },
        { "command": "move_to", "args": {"to": "hardeol"} },
        { "command": "move_to", "args": {"to": "hardbol", "extend": true} },
    ]