diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak new file mode 100644 index 00000000..c61f175c --- /dev/null +++ b/rc/filetype/hare.kak @@ -0,0 +1,122 @@ +# detection +hook global BufCreate .*[.]ha %{ + set-option buffer filetype hare +} + +# initialisation +hook global WinSetOption filetype=hare %{ + require-module 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 -group hare-highlight global WinSetOption filetype=hare %{ + add-highlighter window/hare ref hare + hook -once -always window WinSetOption filetype=*. %{ remove-highlighter window/hare } +} + +# highlighters +provide-module hare %{ + add-highlighter shared/hare regions + add-highlighter shared/hare/code default-region group + add-highlighter shared/hare/comment region // $ fill comment + + add-highlighter shared/hare/rawstring region ` ` group + add-highlighter shared/hare/rawstring/ fill string + + add-highlighter shared/hare/string region '"' (? K } + # remove trailing whitespace on the above line + execute-keys -draft k :hare-trim-indent + } } + + define-command -hidden hare-insert-on-new-line %{ evaluate-commands -draft -itersel %{ + try %{ evaluate-commands -draft -save-regs '/"' %{ + # copy the comment prefix + execute-keys -save-regs '' k s ^\h*\K//\h* y + try %{ + # paste the comment prefix + execute-keys j s ^\h* P + } + } } + try %{ + # remove trailing whitespace on the above line + execute-keys -draft k :hare-trim-indent + } + } } + + define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{ + # remove trailing whitespace + try %{ execute-keys -draft s \h+$ d } + } } + + # TODO + # const/null/void/size are ambiguous + # indentation (copy c-family.kak) +}