Merge remote-tracking branch 'laelath/kakrc-indent-edit'

This commit is contained in:
Maxime Coste 2018-09-12 21:01:33 +10:00
commit b8d312cfe0

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\w]
try %{ execute-keys -draft k <a-x> <a-k> \%\w*[^\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*\Q %val{hook_param} \E$<ret> mGi s \A|.\z<ret> 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>\w*\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 }