# 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 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 %{ 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 } # indent after lines ending with { or ( try %[ execute-keys -draft k [{(]\h*$ j i ] # cleanup trailing white spaces on the previous line execute-keys -draft k :hare-trim-indent # 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 ] } } 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-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 } } } # TODO # const/null/void/size are ambiguous # indentation (copy c-family.kak) §