# 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-insert hare-insert-on-new-line hook window InsertChar \n -group hare-indent hare-indent-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 '"' (?|!|\?|&|\||\.\.(\.)?)" 0:operator # commands 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 kx [{(]\h*$ j i ] # cleanup trailing white spaces on the previous line execute-keys -draft k :hare-trim-indent # indent after match/switch's case statements try %[ execute-keys -draft kx case\h.*=>\h*$ j ] # deindent closing brace(s) when after cursor try %[ execute-keys -draft x ^\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 x s ^\h*\K//\h* y try %{ # paste the comment prefix execute-keys x j x 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 x s \h+$ d } } } §