From 2f0b0d468ce329c97f3fdd05d9c3fd4c0640fd33 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Thu, 30 Aug 2018 17:10:06 -0700 Subject: [PATCH 1/3] 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 } From 852d22a5434d2afa15ae008af3de2be2a4663465 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Thu, 6 Sep 2018 14:56:50 -0700 Subject: [PATCH 2/3] changed opening matching regexes to be simpler --- rc/core/kakrc.kak | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index d9f91238..5eed883d 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -74,19 +74,19 @@ 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] or %sh[\W\S] - try %{ execute-keys -draft k \%(sh)?(?=\S)\W$ 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*[>)}\]]$ mGi s \A|.\z gi 1 = + try %= execute-keys -draft -itersel \h*\Q %val{hook_param} \E$ 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 } + 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 @@ -97,7 +97,7 @@ hook -group kak-highlight global WinSetOption filetype=kak %{ add-highlighter wi 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 + 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 '-' From 22bda7a7d2b7bb48f3d251e7d555f948eb5ffe39 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Tue, 11 Sep 2018 16:15:16 -0700 Subject: [PATCH 3/3] removed unnecessary gi in matching deindent hook --- rc/core/kakrc.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 5eed883d..a0f989c4 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -81,7 +81,7 @@ define-command -hidden kak-indent-on-new-line %{ 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 gi 1 = + try %= execute-keys -draft -itersel \h*\Q %val{hook_param} \E$ mGi s \A|.\z 1 = ~ define-command -hidden kak-indent-on-closing-char %{