Sublime Forum

Cannot save some tasks in ST3

#1

All,

I want to save a macro to do 2 tasks:

1: “New View into File” <-- Duplicate the current screen
2: “Move to Group” <-- Move it to the other panel (right panel), assuming that I have 2 panels open on ST3.

Question 1: Can we save these 2 tasks in macros? I am having a trouble saving it, after recording it.

Instead of using “macro” function to write a macro, I manually created a macro. I saved the below code as test.sublime-macro and try to run it. It ran, but nothing happened.

[
    {"command": "clone_file", "args": {"characters": "\n\n"} },
    {"command": "move_to_group", "args": {"group": "1"}},
]

Question 2: Is this macro incorrect?

Thanks.

0 Likes

#2

The only commands that can appear in Macros are Text commands; i.e. commands that actually modify the buffer. The commands you’re trying to use don’t fall into that category, which is why you can’t record a macro of yourself doing this.

If you check the console (Ctrl+` or View > Show Console) you can see the following errors fall out into the console when you try to run it:

Unknown macro command clone_file
Unknown macro command move_to_group

You could do this by defining your own command, e.g.:

import sublime, sublime_plugin

class CloneSwapCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command ("clone_file")
        self.window.run_command ("move_to_group", {"group": 1})

Saved in Packages/User/clone_swap.py and then bound to a key, e.g.

    {"keys": ["ctrl+alt+shift+s"], "command": "clone_swap"},

The code could obviously be much smarter, for example not running if there’s not a current file or only one view group, selecting the view group to the right of the current group in a smarter way, etc.

2 Likes

#3

Terence, thanks for your reply!

I see that’s what is happening now.

I tried your .py script and it worked great!!! Is there any website that I should look at to learn more on this kind of advanced macro on ST3?

Thanks.

Fumi

0 Likes

#4

Technically, it’s really just a plugin using ST’s API to invoke commands.

1 Like