2024-03-14 18:12:35 -05:00
|
|
|
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
|
2024-03-16 18:29:23 -05:00
|
|
|
|
2024-03-14 18:12:35 -05:00
|
|
|
def get_env():
|
|
|
|
return vim.eval('vimtex#env#get_inner()["name"]')
|
2024-03-16 18:29:23 -05:00
|
|
|
|
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)
|
2024-03-14 18:12:35 -05:00
|
|
|
|
2024-03-16 18:29:23 -05:00
|
|
|
def suppress_none(s):
|
|
|
|
if isinstance(s, str):
|
|
|
|
return s
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2024-03-14 18:12:35 -05:00
|
|
|
endglobal
|
|
|
|
|
2024-03-13 14:07:20 -05:00
|
|
|
priority -10
|
|
|
|
|
2024-03-16 15:55:28 -05:00
|
|
|
context in_env(["itemize", "enumerate"])
|
2024-03-14 19:13:50 -05:00
|
|
|
snippet "\\item\s*\S+.*" "create next item" rb
|
2024-03-14 18:12:35 -05:00
|
|
|
`!p snip.rv = match.group(0)`
|
|
|
|
\item $0
|
|
|
|
endsnippet
|
|
|
|
|
2024-06-03 01:59:00 -05:00
|
|
|
context in_env(["parts"])
|
|
|
|
snippet "\\part\s*\S+.*" "create next part" rb
|
|
|
|
`!p snip.rv = match.group(0)`
|
|
|
|
\part $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)"
|
2024-03-14 18:12:35 -05:00
|
|
|
snippet "\\item\s*$" "exit itemize_like envs" rb
|
|
|
|
endsnippet
|
|
|
|
|
2024-06-03 01:59:00 -05:00
|
|
|
context in_env(["parts"])
|
|
|
|
post_jump "delline_exititemize(snip)"
|
|
|
|
snippet "\\part\s*$" "exit parts" rb
|
|
|
|
endsnippet
|
|
|
|
|
2024-06-02 20:52:07 -05:00
|
|
|
snippet "\\begin\{(itemize|enumerate)\}(\[\w+\])?" "itemize-like envs multiline begin{} / end{}" rb
|
2024-03-16 18:29:23 -05:00
|
|
|
\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
|
|
|
|
|
2024-06-03 01:59:00 -05:00
|
|
|
snippet "\\begin\{parts\}(\[\w+\])?" "parts multiline begin{} / end{}" rb
|
|
|
|
\begin{parts}`!p snip.rv = suppress_none(match.group(1))`
|
|
|
|
\part $0
|
|
|
|
\end{parts}
|
|
|
|
endsnippet
|
|
|
|
|
2024-03-16 18:29:23 -05:00
|
|
|
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
|
2024-03-14 18:12:35 -05:00
|
|
|
\end{`!p snip.rv = match.group(1)`}
|
|
|
|
endsnippet
|
|
|
|
|
2024-06-02 20:52:07 -05:00
|
|
|
priority -30
|
|
|
|
|
2024-03-14 18:12:35 -05:00
|
|
|
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
|
|
|
|
|