# https://nim-lang.org/ # # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.nim(s|ble)? %{ set-option buffer filetype nim } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/nim regions add-highlighter shared/nim/code default-region group add-highlighter shared/nim/single_string region "'" (? s ^\h*#\h* y jgh P } # preserve previous line indent try %{ exec -draft \; K } # cleanup trailing whitespaces from previous line try %{ exec -draft k s \h+$ d } # indent after line ending with const, let, var, ':' or '=' try %{ exec -draft k x (:|=|const|let|var)$ j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group nim-highlight global WinSetOption filetype=nim %{ add-highlighter window/nim ref nim hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/nim } } hook global WinSetOption filetype=nim %{ hook window InsertChar \n -group nim-indent nim-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window ModeChange insert:.* -group nim-trim-indent %{ try %{ exec -draft \; s ^\h+$ d } } hook -once -always window WinSetOption filetype=.* %{ remove-hooks window nim-.+ } }