From b6118c1985db681923066b20efc7ef181231ddc1 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Sat, 16 Mar 2024 01:01:42 -0500 Subject: [PATCH] fix: The exit itemize snippet --- custom-snippets/tex.snippets | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/custom-snippets/tex.snippets b/custom-snippets/tex.snippets index 43c594d..f9ca19d 100644 --- a/custom-snippets/tex.snippets +++ b/custom-snippets/tex.snippets @@ -9,6 +9,11 @@ def itemize_like(): 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 @@ -23,20 +28,17 @@ snippet "\\item\s*\S+.*" "create next item" rb endsnippet context itemize_like() -pre_expand "del snip.buffer[snip.line]; snip.cursor.set(snip.line, len(snip.buffer[snip.line]))" +post_jump "delline_exititemize(snip)" snippet "\\item\s*$" "exit itemize_like envs" rb -$0 endsnippet -context not itemize_like() -snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rb +snippet "\\begin\{((?!itemize|enumerate))\}" "multiline begin{} / end{}" rb \begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} endsnippet -context itemize_like() -snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rb +snippet "\\begin\{(itemize|enumerate)\}" "multiline begin{} / end{}" rb \begin{`!p snip.rv = match.group(1)`} \item $1 \end{`!p snip.rv = match.group(1)`}