added auto deindent to kak files

This commit is contained in:
Justin Frank 2018-08-30 17:10:06 -07:00
parent d57203f41f
commit 2f0b0d468c

View File

@ -74,22 +74,34 @@ define-command -hidden kak-indent-on-new-line %{
try %{ execute-keys -draft \; K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
# indent after line ending with %[\W\S]
try %{ execute-keys -draft k <a-x> <a-k> \%[\W\S]$ <ret> j <a-gt> }
# indent after line ending with %[\W\S] or %sh[\W\S]
try %{ execute-keys -draft k <a-x> <a-k> \%(sh)?(?=\S)\W$ <ret> j <a-gt> }
}
}
define-command -hidden kak-indent-on-closing-matching %~
# align to opening matching brace when alone on a line
try %= execute-keys -draft -itersel <a-h><a-k>\h*[>)}\]]$<ret> mGi s \A|.\z<ret> gi 1<a-&> =
~
define-command -hidden kak-indent-on-closing-char %{
# align to opening matching character when alone on a line
try %{ execute-keys -draft -itersel <a-h><a-k>\h*\Q %val{hook_param} \E$<ret>gi<a-f> %val{hook_param} <a-T>%<a-k>(sh)?\Q %val{hook_param} \E$<ret> s \A|.\z<ret> gi 1<a-&> }
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group kak-highlight global WinSetOption filetype=kak %{ add-highlighter window/kakrc ref kakrc }
hook global WinSetOption filetype=kak %{
hook global WinSetOption filetype=kak %~
hook window InsertChar \n -group kak-indent kak-indent-on-new-line
hook window InsertChar [>)}\]] -group kak-indent kak-indent-on-closing-matching
hook window InsertChar (?![>)}\]])(?=\S)\W -group kak-indent kak-indent-on-closing-char
# cleanup trailing whitespaces on current line insert end
hook window ModeChange insert:.* -group kak-indent %{ try %{ execute-keys -draft \; <a-x> s ^\h+$ <ret> d } }
set-option buffer extra_word_chars '-'
}
~
hook -group kak-highlight global WinSetOption filetype=(?!kak).* %{ remove-highlighter window/kakrc }
hook global WinSetOption filetype=(?!kak).* %{ remove-hooks window kak-indent }