Dynamic placeholders

Asked by Ryan Roler

Is there a way to create dynamic placeholders such that I may produce looping snippets?

snippet param "py.test parameterize decorator" b
@pytest.mark.parameterize(('${1:inpt}', '${2:expected}'), [
`!p from itertools import count
counter = count(3)
while True:
    snip += "(${{{0}: 'test'}}, ${{{1}: 'result'}})${{{2}:,}}".format(
        next(counter), next(counter),next(counter))
    if not snip.rv.endswith(','):
        break`
])$0
endsnippet

I'm looking for this to produce as many lines of ('test', 'result'), as I'd like, and would continue until I remove the trailing comma, at which point, it completes the snippet and moves to the final placeholder. Note the string formatting taking place in each of those lines that makes the first appear as "(${3: 'test'}, ${4: 'result'})${5:,}". Is this at all possible?

I'd also like to thank you for such a wonderful tool.

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

no, it is not. There is no real reason why it shouldn't work, but it is not trivial to implement. The same/similar questions came up before, please have a look at the questions here on launchpad - there are at least 5 or so with more information about this topic.

Revision history for this message
Ryan Roler (ryan-roler) said :
#2

Thanks SirVer, that solved my question.

Revision history for this message
Ryan Roler (ryan-roler) said :
#3

My apologies, I did search through the questions that had titles that seemed relevant prior to asking, but didn't run into anything similar. I suppose that I didn't look hard enough. Thanks again.