diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index fc52378b..a0f989c4 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -74,22 +74,34 @@ define-command -hidden kak-indent-on-new-line %{ try %{ execute-keys -draft \; K } # cleanup trailing whitespaces from previous line try %{ execute-keys -draft k s \h+$ d } - # indent after line ending with %[\W\S] - try %{ execute-keys -draft k \%[\W\S]$ j } + # indent after line ending with %\w*[^\s\w] + try %{ execute-keys -draft k \%\w*[^\s\w]$ j } } } +define-command -hidden kak-indent-on-closing-matching %~ + # align to opening matching brace when alone on a line + try %= execute-keys -draft -itersel \h*\Q %val{hook_param} \E$ mGi s \A|.\z 1 = +~ + +define-command -hidden kak-indent-on-closing-char %{ + # align to opening matching character when alone on a line + try %{ execute-keys -draft -itersel \h*\Q %val{hook_param} \E$gi %val{hook_param} %\w*\Q %val{hook_param} \E$ s \A|.\z gi 1 } +} + # 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 \; s ^\h+$ 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 }