Use the snippet definition as:
post_jump "dynamicsnippet(snip)"
snippet '(\d+)problem' rb
\begin{homeworkProblem}
\begin{enumerate}
`!p snip.rv=create_partprob(int(match.group(1)))`
\end{enumerate}
\end{homeworkProblem}
endsnippet
Attach this piece of code at the end of the desired snippets file.(Probably something like tex.snippets)
global !p
def dynamicsnippet(snip):
# Create anonymous snippet body
anon_snippet_body = ""
# Get start and end line number of expanded snippet
start = snip.snippet_start[0]
end = snip.snippet_end[0]
# Append current line into anonymous snippet
for i in range(start, end + 1):
anon_snippet_body += snip.buffer[i]
anon_snippet_body += "" if i == end else "\n"
# Delete expanded snippet line till second to last line
for i in range(start, end):
del snip.buffer[start]
# Empty last expanded snippet line while preserving the line
snip.buffer[start] = ''
# Expand anonymous snippet
snip.expand_anon(anon_snippet_body)
def create_partprob(n):
out=""
placeholder=1
for _ in range(0,n):
out+=24*" "+"\\item[] $"+f"{placeholder}\\\\\\\\\n"
placeholder+=1
out+=24*" "+" $"+f"{placeholder}\\\\\\\\\n"
placeholder+=1
out=out[:-1]
return out
endglobal
It worked in my editor and Ultisnips, hope it works in yours as well.
Goodluck!
Edit: Use the stack specifically made for vim and vi related questions for such questions. You can find the site here.