diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak index 82dc51cc..6c3f9f52 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -105,7 +105,7 @@ define-command -hidden lua-indent-on-new-line %{ # preserve previous non-empty line indent try %{ execute-keys -draft ^[^\n]+$s\A|.\z) } # indent after start structure - try %{ execute-keys -draft ^[^\n]*\w+[^\n]*$^\h*(else|elseif|for|function|if|while)\b } + try %{ execute-keys -draft ^[^\n]*\w+[^\n]*$\b(else|elseif|for|function|if|while)\b\bend\b } } } @@ -116,8 +116,9 @@ define-command -hidden lua-insert-on-new-line %[ # 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 - try %[ execute-keys -draft k ^x(for|function|if|while) J}iJ ^x(else|end|elseif)$ # Validate previous line and that it is not closed yet - execute-keys -draft oxend ] # auto insert end + try %[ execute-keys -draft k ^x\b[^\n]*(for|function|if|while)\bend\b J}iJ ^x(else|end|elseif)$ # Validate previous line and that it is not closed yet + execute-keys -draft oxend # auto insert end + execute-keys -draft k\(function\bjjA) ] # auto insert ) for anonymous function ] ] ]