Skip to content

[SNIPPET HELP] : How to achieve recursive jumps? #1422

@nikinbaidar

Description

@nikinbaidar

I want to create a snippet such that it allows repeating jump-able nodes. Meaning that, for example, I have a snippet that has two nodes an insertNode(1) and a dynamicNode(2) such that the dynamic node allows me to (recursively) choose between an empty string with t("") or "repeat" whatever I inserted with insertNode(1).

This is do-able with

local function repeat(args)
    return sn(nil, c(1, {
        t(""),
        sn(nil, { i(1), sn(2, t(args[1][1])), d(3, repeat, 2, {}) }),
    }))
end

ls.add_snippets("all", {
    s({trig="tab", desc="Recursive jumps?",}, {
        i(1),
        d(2, repeat, 1, {}),
    }),
}

I took inspiration from rec_ls in the examples for the above and it works as expected as long as args <- insertNode(1) is plain static text. If I insert another jump-able snippet at 1, I want 2 to expand to that and allow the jumps as well and not just the text that was inserted at 1. I hope I could explain my intended behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions