# https://dhall-lang.org # # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](dhall) %{ set-option buffer filetype dhall } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=dhall %{ require-module dhall hook window ModeChange insert:.* -group dhall-trim-indent dhall-trim-indent hook window InsertChar \n -group dhall-indent dhall-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dhall-.+ } } hook -group dhall-highlight global WinSetOption filetype=dhall %{ add-highlighter window/dhall ref dhall hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dhall } } provide-module dhall %[ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/dhall regions add-highlighter shared/dhall/code default-region group add-highlighter shared/dhall/string region '"' (?|\?|λ|\\|\^|⫽|//|\[|\]|\{|\}) 0:operator # Matches built-in functions add-highlighter shared/dhall/code/ regex \b(Natural-fold|Natural-build|Natural-isZero|Natural-even|Natural-odd|Natural-toInteger|Natural-show|Integer-toDouble|Integer-show|Natural-subtract|Double-show|List-build|List-fold|List-length|List-head|List-last|List-indexed|List-reverse|Optional-fold|Optional-build|Text-show)\b 0:keyword # Matches http[s] imports add-highlighter shared/dhall/code/ regex \b(http[s]://\S+)\b(\s+sha256:[a-f0-9]{64}\b)? 0:meta # Matches local imports add-highlighter shared/dhall/code/ regex (~|\.|\.\.|/)\S+ 0:meta # Matches number (natural, integer, double) literals add-highlighter shared/dhall/code/ regex \b(\+|-)?\d+(\.\d+)?(e(\+|-)?\d+)?\b 0:value # Matches union syntax add-highlighter shared/dhall/union region -recurse < < > group add-highlighter shared/dhall/union/sep regex (<|\|)\s*((?:_|[A-Z])(?:[a-zA-Z0-9-/_]*))\s*(?:(:)([^|>]*))? 1:operator 2:attribute 3:operator 4:type add-highlighter shared/dhall/union/end regex > 0:operator # Commands # ‾‾‾‾‾‾‾‾ define-command -hidden dhall-trim-indent %{ # remove trailing white spaces try %{ execute-keys -draft -itersel s \h+$ d } } define-command -hidden dhall-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line try %{ execute-keys -draft k : dhall-trim-indent } # indent after lines ending with let, : or = try %{ execute-keys -draft \; k x (let|:|=)$ j } } } ]