atom / snippets

Atom snippets package
MIT License
205 stars 100 forks source link

Support for Snippet prefix and other values inside Snippet's body #270

Open duckz0r opened 6 years ago

duckz0r commented 6 years ago

I am trying to develop a snippet in which i can use in the body, the snippets prefix, description and/or other values.

For example:

"Snippet x": {
        "prefix": "<my-snippet-prefix>",
    "description": "A prototype of a snippet",
    "types": "html",
    "inputs": ["input1", "input2"],
    "outputs": ["output1", "output2"],
    "body": [
        "<@prefix>",
        "\t${1|@inputs|}",
                "\t${2|@outputs|}",
                "$3",
        "</@prefix>$0"
    ]
}

The point is basically to be able to define values like inputs and outputs (e.g. read from a .txt file and writen on the .json file) instead of writting it all down like:

        "prefix": "<my-snippet-prefix>",
    "description": "A prototype of a snippet",
    "types": "html",
    "body": [
        "<my-snippet-prefix>",
        "\t${1|'input1', 'input2'|}",
                "\t${2|'output1', 'output2'|}",
                "$3",
        "</my-snippet-prefix>$0"
    ]

I don't think this is supported yet, nor the ability to press Ctrl+Space in the code and, within the selected snipped, be able to choose its parameters/values. Is it something doable or am I just missing something?

savetheclocktower commented 5 years ago

This isn’t supported as a built-in feature of snippets. But you can write a command that collects parameters in whatever manner you please and writes the output as a snippet. Here’s an example of how to insert the result of a command as a snippet.