new: Added support for [] options in the begin/end snippets
This commit is contained in:
parent
d426810e81
commit
0677d5a389
1 changed files with 16 additions and 8 deletions
|
@ -7,14 +7,22 @@ def in_env(lst):
|
||||||
return get_env() in lst
|
return get_env() in lst
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_env():
|
def get_env():
|
||||||
return vim.eval('vimtex#env#get_inner()["name"]')
|
return vim.eval('vimtex#env#get_inner()["name"]')
|
||||||
|
|
||||||
def delline_exititemize(snip):
|
def delline_exititemize(snip):
|
||||||
cursorline = snip.cursor[0]
|
cursorline = snip.cursor[0]
|
||||||
del snip.buffer[cursorline]
|
del snip.buffer[cursorline]
|
||||||
snip.buffer.append("\n", cursorline + 1)
|
snip.buffer.append("\n", cursorline + 1)
|
||||||
snip.cursor.set(cursorline + 1, 0)
|
snip.cursor.set(cursorline + 1, 0)
|
||||||
|
|
||||||
|
def suppress_none(s):
|
||||||
|
if isinstance(s, str):
|
||||||
|
return s
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
endglobal
|
endglobal
|
||||||
|
|
||||||
priority -10
|
priority -10
|
||||||
|
@ -30,20 +38,20 @@ post_jump "delline_exititemize(snip)"
|
||||||
snippet "\\item\s*$" "exit itemize_like envs" rb
|
snippet "\\item\s*$" "exit itemize_like envs" rb
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet "\\begin\{(itemize|enumerate)\}" "multiline begin{} / end{}" rb
|
snippet "\\begin\{(itemize|enumerate)\}(\[\w+\])?" "multiline begin{} / end{}" rb
|
||||||
\begin{`!p snip.rv = match.group(1)`}
|
\begin{`!p snip.rv = match.group(1)`}`!p snip.rv = suppress_none(match.group(2))`
|
||||||
\item $0
|
\item $0
|
||||||
\end{`!p snip.rv = match.group(1)`}
|
\end{`!p snip.rv = match.group(1)`}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet "\\begin\{((?!itemize|enumerate))\}" "multiline begin{} / end{}" rb
|
|
||||||
\begin{`!p snip.rv = match.group(1)`}
|
|
||||||
$0
|
|
||||||
\end{`!p snip.rv = match.group(1)`}
|
|
||||||
endsnippet
|
|
||||||
|
|
||||||
priority -20
|
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))`
|
||||||
|
$0
|
||||||
|
\end{`!p snip.rv = match.group(1)`}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
|
snippet "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" ri
|
||||||
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
|
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
Loading…
Reference in a new issue