diff options
| -rw-r--r-- | rc/filetype/lua.kak | 2 | ||||
| -rw-r--r-- | test/indent/lua/insert-end-only-when-needed/in | 14 | ||||
| -rw-r--r-- | test/indent/lua/insert-end-only-when-needed/out | 18 |
3 files changed, 31 insertions, 3 deletions
diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak index 9660253d..1dd0178a 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -136,7 +136,7 @@ define-command -hidden lua-insert-on-new-line %[ <a-k>^\h*\b(else|elseif|do|for|function|if|while)\b|[^\n]\bfunction\b\h*[(]<ret> \ <a-K>\bend\b<ret> # check that the block is empty and is not closed on a different line - execute-keys -draft <a-a>i <a-K>^[^\n]*\n[^\n]*\n<ret> j<a-x> <a-K>^<c-r>x\b(else|elseif|end)\b<ret> + execute-keys -draft <a-a>i <a-K>^[^\n]+\n[^\n]+\n<ret> j<a-x> <a-K>^<c-r>x\b(else|elseif|end)\b<ret> # auto insert end execute-keys -draft o<c-r>xend<esc> # auto insert ) for anonymous function diff --git a/test/indent/lua/insert-end-only-when-needed/in b/test/indent/lua/insert-end-only-when-needed/in index 14415ac6..9c880220 100644 --- a/test/indent/lua/insert-end-only-when-needed/in +++ b/test/indent/lua/insert-end-only-when-needed/in @@ -3,7 +3,19 @@ end function fun2()%( ) - function fun3() if true then%( ) end + +function fun4() + if true then + return 10 + else%( ) +end + +function fun5() + if true then%( ) + return 10 +end + +local str = "while"%( ) diff --git a/test/indent/lua/insert-end-only-when-needed/out b/test/indent/lua/insert-end-only-when-needed/out index b1644048..f2b9fa25 100644 --- a/test/indent/lua/insert-end-only-when-needed/out +++ b/test/indent/lua/insert-end-only-when-needed/out @@ -6,9 +6,25 @@ function fun2() foo() end - function fun3() if true then foo() end end + +function fun4() + if true then + return 10 + else + foo() + end +end + +function fun5() + if true then + foo() + return 10 +end + +local str = "while" +foo() |
