Skip to content

Is possible to create a snippet that when expanded it insert a line in the start of the file? #383

Answered by L3MON4D3
LaBatata101 asked this question in Q&A
Discussion options

You must be logged in to vote

Ouh, yeah that's possible: just create a functionNode without arg nodes. The code in there will only run once during the initial expansion and you won't see it as long as it doesn't return any text returns an empty string.

s("dataclass", {
    <other nodes>, 
    f(insert_dataclass_at_beginning, {})
})

This will be more straightforward once pre_expand/post_expand-callbacks are added.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@LaBatata101
Comment options

@L3MON4D3
Comment options

@LaBatata101
Comment options

Answer selected by LaBatata101
Comment options

You must be logged in to vote
2 replies
@L3MON4D3
Comment options

@LaBatata101
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants