From 705712f13b9e496cbf9cdf7623916ddf8d0b5a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Sat, 5 Sep 2020 15:49:50 +0200 Subject: [PATCH] Improve latex support. Auto insert "\end{[word]}" for "\begin{[word]}". --- rc/filetype/latex.kak | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rc/filetype/latex.kak b/rc/filetype/latex.kak index a872ad14..98b64028 100644 --- a/rc/filetype/latex.kak +++ b/rc/filetype/latex.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=latex %( hook window InsertChar \} -group latex-indent %{ latex-indent-closing-brace } hook window ModeChange pop:insert:.* -group latex-indent %{ latex-trim-indent } hook -once -always window WinSetOption filetype=.* %{ remove-hooks latex-indent } + hook window InsertChar \n -group latex-insert latex-insert-on-new-line ) hook -group latex-highlight global WinSetOption filetype=latex %{ @@ -93,4 +94,22 @@ define-command -hidden latex-indent-closing-brace %( ) ) +define-command -hidden latex-insert-on-new-line %( + evaluate-commands -no-hooks -draft -itersel %( + # Wisely add "\end{...}". + evaluate-commands -save-regs xz %( + # Save previous line indent in register x. + try %( execute-keys -draft ks^\h+"xy ) catch %( reg x '' ) + # Save item of begin in register z. + try %( execute-keys -draft ks\{.*\}"zy ) catch %( reg z '' ) + try %( + # Validate previous line and that it is not closed yet. + execute-keys -draft k ^x\h*\\begin\{.*\} J}iJ ^x(\\end\z\}) + # Auto insert "\end{...}". + execute-keys -draft ox\endz + ) + ) + ) +) + ~