From f440a1c109b7e7050b9088ace138eea0d474646c Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Tue, 13 Jul 2021 13:21:47 -0300 Subject: [PATCH] Lua: insert comment prefix *after* the indent This fixes a bug in how the Lua scripts handle new comment lines. Currently if we have a comment that is indented, when we add a new line it inserts the `--` prefix before the automatic indentation. ``` --ABC -- XYZ ``` After the fix, it correctly inserts the comment prefix after the indentation: ``` --ABC --XYZ ``` The solution I used is inspired by the ruby.kak script. --- rc/filetype/lua.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak index 05684c14..891a8713 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -112,7 +112,7 @@ define-command -hidden lua-indent-on-new-line %{ define-command -hidden lua-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ # copy -- comment prefix and following white spaces - try %{ execute-keys -draft ks^\h*\K--\h* y gh j P } + try %{ execute-keys -draft ks^\h*\K--\h* y gh j P } # wisely add end structure evaluate-commands -save-regs x %[ try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } # Save previous line indent in register x