dhall.kak (3897B)
1 # https://dhall-lang.org 2 # 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](dhall) %{ 8 set-option buffer filetype dhall 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=dhall %{ 15 require-module dhall 16 17 hook window ModeChange pop:insert:.* -group dhall-trim-indent dhall-trim-indent 18 hook window InsertChar \n -group dhall-insert dhall-insert-on-new-line 19 hook window InsertChar \n -group dhall-indent dhall-indent-on-new-line 20 21 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dhall-.+ } 22 } 23 24 hook -group dhall-highlight global WinSetOption filetype=dhall %{ 25 add-highlighter window/dhall ref dhall 26 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/dhall } 27 } 28 29 30 provide-module dhall %[ 31 32 # Highlighters 33 # ‾‾‾‾‾‾‾‾‾‾‾‾ 34 35 add-highlighter shared/dhall regions 36 add-highlighter shared/dhall/code default-region group 37 add-highlighter shared/dhall/string region '"' (?<!\\)(\\\\)*" fill string 38 add-highlighter shared/dhall/comment region -recurse \{- \{- -\} fill comment 39 add-highlighter shared/dhall/line_comment region -- $ fill comment 40 41 # Matches multi-line string literals 42 add-highlighter shared/dhall/multiline_string region \Q''\E$ [^']''[^'] fill string 43 44 # Matches quoted labels 45 add-highlighter shared/dhall/quoted_label region ` ` fill normal 46 47 # Matches built-in types 48 add-highlighter shared/dhall/code/ regex \b(Location|Sort|Kind|Type|Text|Bool|Natural|Integer|Double|List|Optional|\{\})\b 0:type 49 50 # Matches built-in keywords 51 add-highlighter shared/dhall/code/ regex \b(if|then|else|let|in|using|missing|as|merge|toMap)\b 0:keyword 52 53 # Matches bulit-in values 54 add-highlighter shared/dhall/code/ regex \b(True|False|Some|None|-?Infinity|\{=\}|NaN)\b 0:value 55 56 # Matches built-in operators 57 add-highlighter shared/dhall/code/ regex (,|:|\|\||&&|==|!=|=|\+|\*|\+\+|#|⩓|//\\\\|→|->|\?|λ|\\|\^|⫽|//|\[|\]|\{|\}) 0:operator 58 59 # Matches built-in functions 60 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 61 62 # Matches http[s] imports 63 add-highlighter shared/dhall/code/ regex \b(http[s]://\S+)\b(\s+sha256:[a-f0-9]{64}\b)? 0:meta 64 65 # Matches local imports 66 add-highlighter shared/dhall/code/ regex (~|\.|\.\.|/)\S+ 0:meta 67 68 # Matches number (natural, integer, double) literals 69 add-highlighter shared/dhall/code/ regex \b(\+|-)?\d+(\.\d+)?(e(\+|-)?\d+)?\b 0:value 70 71 # Matches union syntax 72 add-highlighter shared/dhall/union region -recurse < < > group 73 add-highlighter shared/dhall/union/sep regex (<|\|)\s*((?:_|[A-Z])(?:[a-zA-Z0-9-/_]*))\s*(?:(:)([^|>]*))? 1:operator 2:attribute 3:operator 4:type 74 add-highlighter shared/dhall/union/end regex > 0:operator 75 76 # Commands 77 # ‾‾‾‾‾‾‾‾ 78 79 define-command -hidden dhall-trim-indent %{ 80 # remove trailing white spaces 81 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 82 } 83 84 define-command -hidden dhall-insert-on-new-line %{ 85 evaluate-commands -draft -itersel %{ 86 # copy -- comments prefix and following white spaces 87 try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P } 88 } 89 } 90 define-command -hidden dhall-indent-on-new-line %{ 91 evaluate-commands -draft -itersel %{ 92 # preserve previous line indent 93 try %{ execute-keys -draft \; K <a-&> } 94 # filter previous line 95 try %{ execute-keys -draft k : dhall-trim-indent <ret> } 96 # indent after lines ending with let, : or = 97 try %{ execute-keys -draft \; k x <a-k> (\blet|:|=)$ <ret> j <a-gt> } 98 } 99 } 100 101 ]