parent
a2fc89a6ec
commit
65258934d3
|
@ -52,13 +52,6 @@ define-command lua-alternative-file -docstring 'Jump to the alternate file (impl
|
|||
printf %s\\n "edit $altfile"
|
||||
}}
|
||||
|
||||
define-command -hidden lua-filter-around-selections %{
|
||||
evaluate-commands -no-hooks -draft -itersel %{
|
||||
# remove trailing white spaces
|
||||
try %{ execute-keys -draft <a-x>s\h+$<ret>d }
|
||||
}
|
||||
}
|
||||
|
||||
define-command -hidden lua-indent-on-char %{
|
||||
evaluate-commands -no-hooks -draft -itersel %{
|
||||
# align middle and end structures to start and indent when necessary, elseif is already covered by else
|
||||
|
@ -71,24 +64,25 @@ define-command -hidden lua-indent-on-new-line %{
|
|||
evaluate-commands -no-hooks -draft -itersel %{
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft <space>K<a-&> }
|
||||
# filter previous line
|
||||
try %{ execute-keys -draft k:lua-filter-around-selections<ret> }
|
||||
# remove trailing white spaces from previous line
|
||||
try %{ execute-keys -draft k<a-x>s\h+$<ret>d }
|
||||
# indent after start structure
|
||||
try %{ execute-keys -draft k<a-x><a-k>^\h*(else|elseif|for|function|if|while)\b<ret>j<a-gt> }
|
||||
}
|
||||
}
|
||||
|
||||
define-command -hidden lua-insert-on-new-line %{
|
||||
evaluate-commands -no-hooks -draft -itersel %{
|
||||
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 k<a-x>s^\h*\K--\h*<ret>yghjP }
|
||||
# wisely add end structure
|
||||
evaluate-commands -save-regs x %{
|
||||
try %{ execute-keys -draft k<a-x>s^\h+<ret>"xy } catch %{ reg x '' }
|
||||
try %{ execute-keys -draft k<a-x><a-k>^<c-r>x(for|function|if|while)<ret>j<a-a>iX<a-\;>K<a-K>^<c-r>x(for|function|if|while).*\n<c-r>x(else|end|elseif[^\n]*)$<ret>jxypjaend<esc><a-lt> }
|
||||
}
|
||||
}
|
||||
}
|
||||
evaluate-commands -save-regs x %[
|
||||
try %{ execute-keys -draft k<a-x>s^\h+<ret>"xy } catch %{ reg x '' } # Save previous line indent in register x
|
||||
try %[ execute-keys -draft k<a-x> <a-k>^<c-r>x(for|function|if|while)<ret> J}iJ<a-x> <a-K>^<c-r>x(else|end|elseif)$<ret> # Validate previous line and that it is not closed yet
|
||||
execute-keys -draft o<c-r>xend<esc> ] # auto insert end
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
# Initialization
|
||||
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
||||
|
@ -97,8 +91,8 @@ hook -group lua-highlight global WinSetOption filetype=lua %{ add-highlighter wi
|
|||
|
||||
hook global WinSetOption filetype=lua %{
|
||||
hook window InsertChar .* -group lua-indent lua-indent-on-char
|
||||
hook window InsertChar \n -group lua-insert lua-insert-on-new-line
|
||||
hook window InsertChar \n -group lua-indent lua-indent-on-new-line
|
||||
hook window InsertChar \n -group lua-insert lua-insert-on-new-line
|
||||
|
||||
alias window alt lua-alternative-file
|
||||
}
|
||||
|
|
1
test/indent/lua/insert-end-only-when-needed/cmd
Normal file
1
test/indent/lua/insert-end-only-when-needed/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>foo()<esc>
|
9
test/indent/lua/insert-end-only-when-needed/in
Normal file
9
test/indent/lua/insert-end-only-when-needed/in
Normal file
|
@ -0,0 +1,9 @@
|
|||
function fun1()%( )
|
||||
end
|
||||
|
||||
function fun2()%( )
|
||||
|
||||
|
||||
function fun3()
|
||||
if true then%( )
|
||||
end
|
14
test/indent/lua/insert-end-only-when-needed/out
Normal file
14
test/indent/lua/insert-end-only-when-needed/out
Normal file
|
@ -0,0 +1,14 @@
|
|||
function fun1()
|
||||
foo()
|
||||
end
|
||||
|
||||
function fun2()
|
||||
foo()
|
||||
end
|
||||
|
||||
|
||||
function fun3()
|
||||
if true then
|
||||
foo()
|
||||
end
|
||||
end
|
3
test/indent/lua/insert-end-only-when-needed/rc
Normal file
3
test/indent/lua/insert-end-only-when-needed/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/base/lua.kak"
|
||||
set buffer filetype lua
|
1
test/regression/1525-lua-indent-error/cmd
Normal file
1
test/regression/1525-lua-indent-error/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>foo()<esc>
|
2
test/regression/1525-lua-indent-error/in
Normal file
2
test/regression/1525-lua-indent-error/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugdemo = {}
|
||||
function bugdemo.bug()%( )
|
4
test/regression/1525-lua-indent-error/out
Normal file
4
test/regression/1525-lua-indent-error/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
bugdemo = {}
|
||||
function bugdemo.bug()
|
||||
foo()
|
||||
end
|
3
test/regression/1525-lua-indent-error/rc
Normal file
3
test/regression/1525-lua-indent-error/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/base/lua.kak"
|
||||
set buffer filetype lua
|
Loading…
Reference in New Issue
Block a user