my-nvim-config/custom-snippets/tex.snippets

52 lines
1.2 KiB
Text

global !p
# def math():
# return vim.eval('vimtex#syntax#in_mathzone()') == '1'
def itemize_like():
try:
return get_env() in ["itemize", "enumerate"]
except:
return False
def get_env():
return vim.eval('vimtex#env#get_inner()["name"]')
def delline_exititemize(snip):
cursorline = snip.cursor[0]
del snip.buffer[cursorline]
snip.buffer.append("\n", cursorline + 1)
snip.cursor.set(cursorline + 1, 0)
endglobal
priority -10
extends tex
context itemize_like()
snippet "\\item\s*\S+.*" "create next item" rb
`!p snip.rv = match.group(0)`
\item $0
endsnippet
context itemize_like()
post_jump "delline_exititemize(snip)"
snippet "\\item\s*$" "exit itemize_like envs" rb
endsnippet
snippet "\\begin\{((?!itemize|enumerate))\}" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}
$1
\end{`!p snip.rv = match.group(1)`}
endsnippet
snippet "\\begin\{(itemize|enumerate)\}" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}
\item $1
\end{`!p snip.rv = match.group(1)`}
endsnippet
priority -20
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
endsnippet