From 2f0b0d468ce329c97f3fdd05d9c3fd4c0640fd33 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Thu, 30 Aug 2018 17:10:06 -0700 Subject: [PATCH] added auto deindent to kak files --- rc/core/kakrc.kak | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index fc52378b..d9f91238 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] or %sh[\W\S] + try %{ execute-keys -draft k \%(sh)?(?=\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*[>)}\]]$ mGi s \A|.\z gi 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} %(sh)?\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 }