Sublime Forum

Macros do not record code folding?

#1

Hello community.

Am posting to confirm that macro recording do not support code folding operations?

Just want to be sure that I don’t need to do anything special to capture code folding commands in a macro.

Thanks!

0 Likes

#2

Do you have any examples that are not working ? Code folding (or at least the commands behind them) are all view based, meaning that they only make sense in an open text document and macros are designed to run only view based commands, so theoretically it should work. I tried a couple fold related commands from a macro & seems to work for me.

0 Likes

#3

I tried to record a macro that did the following

  • CMD+Up Arrow (go to start of file)
  • CMD+K, CMD+J (unfold all code)
  • CMD+K, CMD+4 (code fold level 4)

After stopping the recording I just get a message indicating that 1 command was recorded, the 1st command to put cursor at top of file.

Is recording these key commands the right way to go about it?

0 Likes

#4

I can confirm that it indeed records only the first command (go to start of file). Maybe the built in macro recorder has some problems in recording certain commands ? IDK. I almost never use the recorder. On rare occasions, when I have to use a macro, I simply manually construct the .sublime-macro file & use it with a key binding.

For your set of actions, the macro file will be

[
    { "command": "move_to", "args": { "to": "bof" }, },
    { "command": "unfold_all" },
    { "command": "fold_by_level", "args": { "level": 4 } },
]

Simply save this as a .sublime-macro extension file (can be any name) in your User folder and use it via a key binding.

Example key binding.

{
        "keys": ["alt+y"],
        "command": "run_macro_file",
        "args": {
            "file": "Packages/User/<my_macro_name>.sublime-macro"
        },
}
1 Like

#5

Wow! That’s amazing. Thanks so much for sharing. Really appreciate it!

0 Likes