Search code examples
macrossublimetext3sublimetext2sublimetextsublime-text-plugin

Why the macro doesn't work?


Here is the macro, whcih, for some reason, doesn't work:

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

I can do the same things via plugin, but I don't like to use it here:

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})

Why the macro doesn't work?


Solution

  • The macro doesn't work because the JSON that you're using to define it is invalid; the args key needs to be wrapped in double quotes, but it's not. As a result the Macro won't load and thus can't execute.

    If your color scheme supports it, the invalid characters will be highlighted to indicate the problem for you.

    A corrected version would be:

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