Sublime Forum

Random behaviour with macros

#1

In the latest version of Sublime Text (3.2.2), my macros don’t work as they did.

They’re pretty simple. Cut text, insert text and paste text. The result, as you can see, is quite random (I’m repeating the same action all the time.)

sublime-macro-bug

Here it is the marco

[
    {
        "args":
        {
            "to": "tag"
        },
        "command": "expand_selection"
    },
    {
        "args": null,
        "command": "cut"
    },
    {
        "args":
        {
            "characters": "${_(\""
        },
        "command": "insert"
    },
    {
        "args": null,
        "command": "paste"
    },
    {
        "args":
        {
            "characters": "\")}"
        },
        "command": "insert"
    }
]

I am using “Textmate Freemarker Bundle” and a key binding linked to the macro.

0 Likes

Need help creating a macro
#2

I can’t replicate that locally; the macro always seems to do the same thing. Is there anything special about the key binding that you’re using? Have you tried temporarily reverting Sublime to the default state and then applying that key binding and macro to see if the same thing happens?

0 Likes

#3

Hi @OdatNurd. I reverted Sublime to the default state.

No key binding. No extra package. Html file type.

FYI: this was the key binding

{ "keys": ["ctrl+keypad_multiply"], "command": "run_macro_file", "args": {"file": "Packages/User/gettext-tagselect-freemarker.sublime-macro"} },
0 Likes

#4

I’m pretty sure the problem is with the “expand selection to tag” logic, as your caret is in a different place each time

0 Likes

#5

I’m not sure. I made a workaround without cutting the text and it works fine. I think the problem is the “cut” and “paste”.

This is the macro I am using now:

[
{
    "args":
    {
        "to": "tag"
    },
    "command": "expand_selection"
},
{
    "args":
    {
        "by": "characters",
        "forward": false
    },
    "command": "move"
},
{
    "args":
    {
        "characters": "${_(\""
    },
    "command": "insert"
},
{
    "args":
    {
        "to": "tag"
    },
    "command": "expand_selection"
},
{
    "args":
    {
        "by": "characters",
        "forward": true
    },
    "command": "move"
},
{
    "args":
    {
        "characters": "\")}"
    },
    "command": "insert"
}

]

0 Likes

#6

For what it’s worth, you could shorten your macro up to something like:

[
    {
        "args":
        {
            "to": "tag"
        },
        "command": "expand_selection"
    },
    {
        "command": "insert_snippet",
        "args": {
            "contents": "\\${_(\"${SELECTION}\")}"
        },
    }
]

That just wraps the selection directly with the text you want to surround it with, without having to do any cut/paste or cursor actions.

1 Like

#7

I didn’t know that approach. It works like a charm. Thank you

0 Likes