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

61 lines
1.4 KiB
Text
Raw Normal View History

global !p
# def math():
# return vim.eval('vimtex#syntax#in_mathzone()') == '1'
2024-03-16 15:55:28 -05:00
def in_env(lst):
2024-03-15 09:21:36 -05:00
try:
2024-03-16 15:55:28 -05:00
return get_env() in lst
2024-03-15 09:21:36 -05:00
except:
return False
def get_env():
return vim.eval('vimtex#env#get_inner()["name"]')
2024-03-16 01:01:42 -05:00
def delline_exititemize(snip):
cursorline = snip.cursor[0]
del snip.buffer[cursorline]
snip.buffer.append("\n", cursorline + 1)
snip.cursor.set(cursorline + 1, 0)
def suppress_none(s):
if isinstance(s, str):
return s
else:
return ""
endglobal
2024-03-13 14:07:20 -05:00
priority -10
2024-03-16 15:55:28 -05:00
context in_env(["itemize", "enumerate"])
snippet "\\item\s*\S+.*" "create next item" rb
`!p snip.rv = match.group(0)`
\item $0
endsnippet
2024-03-16 15:55:28 -05:00
context in_env(["itemize", "enumerate"])
2024-03-16 01:01:42 -05:00
post_jump "delline_exititemize(snip)"
snippet "\\item\s*$" "exit itemize_like envs" rb
endsnippet
snippet "\\begin\{(itemize|enumerate)\}(\[\w+\])?" "itemize-like envs multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}`!p snip.rv = suppress_none(match.group(2))`
2024-03-16 15:55:28 -05:00
\item $0
2024-03-13 14:07:20 -05:00
\end{`!p snip.rv = match.group(1)`}
endsnippet
priority -20
snippet "\\begin\{(\w+)\}(\[\w+\])?" "multiline begin{} / end{}" rb
\begin{`!p snip.rv = match.group(1)`}`!p snip.rv = suppress_none(match.group(2))`
2024-03-16 15:55:28 -05:00
$0
\end{`!p snip.rv = match.group(1)`}
endsnippet
priority -30
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
2024-03-13 14:07:20 -05:00
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
endsnippet