diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index c61f175c..31007067 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -9,6 +9,8 @@ hook global WinSetOption filetype=hare %{ hook window ModeChange pop:insert:.* -group hare-trim-indent hare-trim-indent hook window InsertChar \n -group hare-indent hare-indent-on-new-line hook window InsertChar \n -group hare-insert hare-insert-on-new-line + hook window InsertChar \{ -group hare-indent hare-indent-on-opening-curly-brace + hook window InsertChar \} -group hare-indent hare-indent-on-closing-curly-brace } hook -group hare-highlight global WinSetOption filetype=hare %{ @@ -17,7 +19,7 @@ hook -group hare-highlight global WinSetOption filetype=hare %{ } # highlighters -provide-module hare %{ +provide-module hare %§ add-highlighter shared/hare regions add-highlighter shared/hare/code default-region group add-highlighter shared/hare/comment region // $ fill comment @@ -92,6 +94,14 @@ provide-module hare %{ define-command -hidden hare-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # preserve indentation on new lines try %{ execute-keys -draft K } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j i ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # deindent closing brace(s) when after cursor + try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] # remove trailing whitespace on the above line execute-keys -draft k :hare-trim-indent } } @@ -111,6 +121,16 @@ provide-module hare %{ } } } + define-command -hidden hare-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] + ] + + define-command -hidden hare-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] + ] + define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{ # remove trailing whitespace try %{ execute-keys -draft s \h+$ d } @@ -119,4 +139,4 @@ provide-module hare %{ # TODO # const/null/void/size are ambiguous # indentation (copy c-family.kak) -} + § diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 1094fbba..803a96fe 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -118,7 +118,7 @@ hook global BufSetOption filetype=perl %{ set-option buffer comment_block_end ']' } -hook global BufSetOption filetype=(pug|zig|cue) %{ +hook global BufSetOption filetype=(pug|zig|cue|hare) %{ set-option buffer comment_line '//' }