Buongiorno a tutti, sono uno studente (non un programmatore);
non avendo notevoli abilità con Javascript, mi affido a voi per modificare questo frammento di codice scritto di Python:
global !p
def create_matrix_placeholders(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
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_matrix(cols, rows, sep, start, end):
res = ""
placeholder = 1
for _ in range(0, int(rows)):
res += start + f"${placeholder} "
placeholder += 1
for _ in range(0, int(cols) - 1):
res += sep + f" ${placeholder} "
placeholder += 1
res += end
return res[:-1]
endglobal
post_jump "create_matrix_placeholders(snip)"
snippet 'arr(\d+),(\d+)' "LaTeX array" br
\begin{array}{`!p
orient = ""
for _ in range(0, int(match.group(1))): orient += "l"
snip.rv = orient`}
`!p
snip.rv = create_matrix(match.group(1), match.group(2), "&", "\t", "\\\\\\\\\n")
`$0
\end{array}
endsnippet
PS: questo snippet è stato preso da Lervag/Ultisnips; https://github.com/SirVer/ultisnips/blob/master/doc/examples/tabstop-generation/README.md
Ringrazio in anticipo tutti coloro che aiuteranno!!