hook global BufCreate .*\.odin %{ set-option buffer filetype odin } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=odin %{ require-module odin set-option window static_words %opt{odin_static_words} # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group odin-trim-indent %{ try %{ execute-keys -draft xs^\h+$d } } hook window InsertChar \n -group odin-insert odin-insert-on-new-line hook window InsertChar \n -group odin-indent odin-indent-on-new-line hook window InsertChar \{ -group odin-indent odin-indent-on-opening-curly-brace hook window InsertChar \} -group odin-indent odin-indent-on-closing-curly-brace hook -once -always window WinSetOption filetype=.* %{ remove-hooks window odin-.+ } } hook -group odin-highlight global WinSetOption filetype=odin %{ add-highlighter window/odin ref odin hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/odin } } provide-module odin %§ add-highlighter shared/odin regions add-highlighter shared/odin/code default-region group add-highlighter shared/odin/string region %{(?kx s ^\h*\K/{2,}\h* yP } ] define-command -hidden odin-indent-on-new-line %< evaluate-commands -draft -itersel %= # preserve previous line indent try %{ execute-keys -draft K } # indent after lines ending with { or ( try %[ execute-keys -draft kx [{(]\h*$ j ] # cleanup trailing white spaces on the previous line try %{ execute-keys -draft kx s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # indent after a switch's case/default statements try %[ execute-keys -draft kx ^\h*(case|default).*:$ j ] # indent after keywords try %[ execute-keys -draft )MB \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] # deindent closing brace(s) when after cursor try %[ execute-keys -draft x ^\h*[})] gh / [})] m 1 ] = > define-command -hidden odin-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 odin-indent-on-closing-curly-brace %[ # align to opening curly brace when alone on a line try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] ] evaluate-commands %sh{ values='false true nil ---' types='bool b8 b16 b32 b64 int i8 i16 i32 i64 i128 uint u8 u16 u32 u64 u128 uintptr i16le i32le i64le i128le u16le u32le u64le u128le i16be i32be i64be i128be u16be u32be u64be u128be f16 f32 f64 f16le f32le f64le f16be f32be f64be complex32 complex64 complex128 quaternion64 quaternion128 quaternion256 rune string cstring rawptr typeid any' keywords='asm auto_cast bit_set break case cast context continue defer distinct do dynamic else enum fallthrough for foreign if import in map not_in or_else or_return package proc return struct switch transmute typeid union using when where' attributes='' # ---------------------------------------------------------------------------------------------- # join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } # ---------------------------------------------------------------------------------------------- # add_highlighter() { printf "add-highlighter shared/odin/code/ regex %s %s\n" "$1" "$2"; } # ---------------------------------------------------------------------------------------------- # add_word_highlighter() { while [ $# -gt 0 ]; do words=$1 face=$2; shift 2 regex="\\b($(join "${words}" '|'))\\b" add_highlighter "$regex" "1:$face" done } # ---------------------------------------------------------------------------------------------- # printf %s\\n "declare-option str-list odin_static_words $(join "${values} ${types} ${keywords} ${attributes} ${modules}" ' ')" # ---------------------------------------------------------------------------------------------- # add_word_highlighter "$values" "value" "$types" "type" "$keywords" "keyword" "$attributes" "attribute" # ---------------------------------------------------------------------------------------------- # } §