diff --git a/rc/filetype/dhall.kak b/rc/filetype/dhall.kak new file mode 100644 index 00000000..0dcd8d28 --- /dev/null +++ b/rc/filetype/dhall.kak @@ -0,0 +1,90 @@ +# 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 } + } +} + +] diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 586b516b..39d62501 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -20,7 +20,7 @@ hook global BufSetOption filetype=(c|cpp|dart|go|java|javascript|objc|php|rust|s set-option buffer comment_block_end '*/' } -hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm) %{ +hook global BufSetOption filetype=(cabal|haskell|moon|idris|elm|dhall) %{ set-option buffer comment_line '--' set-option buffer comment_block_begin '{-' set-option buffer comment_block_end '-}'