kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

elvish.kak (3524B)


      1 # Syntax highlighting and indentation for Elvish (https://elv.sh)
      2 
      3 hook global BufCreate .*\.elv %{
      4     set-option buffer filetype elvish
      5 }
      6 
      7 hook global WinSetOption filetype=elvish %<
      8     require-module elvish
      9 
     10     hook window ModeChange pop:insert:.* -group elvish-trim-indent elvish-trim-indent
     11     hook window InsertChar \n -group elvish-insert elvish-indent
     12     hook window InsertChar [\]})] -group elvish-insert elvish-deindent
     13     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elvish-.+ }
     14 >
     15 
     16 hook -group elvish-highlight global WinSetOption filetype=elvish %{
     17     add-highlighter window/elvish ref elvish
     18     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elvish }
     19 }
     20 
     21 provide-module elvish %§
     22 
     23 add-highlighter shared/elvish regions
     24 add-highlighter shared/elvish/code default-region group
     25 add-highlighter shared/elvish/double_string region '"' (?<!\\)(\\\\)*" fill string
     26 add-highlighter shared/elvish/single_string region "'" ('')*' fill string
     27 add-highlighter shared/elvish/comment region '#' $ fill comment
     28 
     29 add-highlighter shared/elvish/code/variable regex \$[\w\d-_:~]+ 0:variable
     30 add-highlighter shared/elvish/code/variable_in_assignment regex (?:^|\{\s|\(|\||\;)\h*(?:var|set|tmp|del)((?:\h+[\w\d-_:~]+)*) 1:variable
     31 add-highlighter shared/elvish/code/variable_in_for regex (?:^|\{\s|\(|\||\;)\h*for\h+([\w\d-_:~]*) 1:variable
     32 add-highlighter shared/elvish/code/variable_in_catch regex \}\h+(?:catch|except)\h+([\w\d-_:~]*) 1:variable
     33 
     34 add-highlighter shared/elvish/code/builtin regex (?:^|\{\s|\(|\||\;)\h*(!=|!=s|%|\*|\+|-gc|-ifaddrs|-log|-override-wcwidth|-stack|-|/|<|<=|<=s|<s|==|==s|>|>=|>=s|>s|all|assoc|base|bool|break|call|cd|compare|constantly|continue|count|defer|deprecate|dissoc|drop|each|eawk|echo|eq|eval|exact-num|exec|exit|external|fail|fg|float64|from-json|from-lines|from-terminated|get-env|has-env|has-external|has-key|has-value|is|keys|kind-of|make-map|multi-error|nop|not-eq|not|ns|num|one|only-bytes|only-values|order|peach|pprint|print|printf|put|rand|randint|range|read-line|read-upto|repeat|repr|resolve|return|run-parallel|search-external|set-env|show|sleep|slurp|src|styled|styled-segment|take|tilde-abbr|time|to-json|to-lines|to-string|to-terminated|unset-env|use-mod|wcswidth)(?![-:])\b 1:builtin
     35 add-highlighter shared/elvish/code/keyword regex (?:^|\{\s|\(|\||\;)\h*(use|var|set|tmp|del|and|or|coalesce|pragma|while|for|try|fn|if)(?![-:])\b 1:keyword
     36 add-highlighter shared/elvish/code/keyword_block regex \}\h+(catch|elif|else|except|finally)(?![-:])\b 1:keyword
     37 
     38 add-highlighter shared/elvish/code/metachar regex [*?|&\;<>()[\]{}] 0:operator
     39 
     40 define-command -hidden elvish-trim-indent %{
     41     evaluate-commands -no-hooks -draft -itersel %{
     42         execute-keys x
     43         # remove trailing white spaces
     44         try %{ execute-keys -draft s \h + $ <ret> d }
     45     }
     46 }
     47 
     48 define-command -hidden elvish-indent %< evaluate-commands -draft -itersel %<
     49     execute-keys <semicolon>
     50     try %<
     51         # if the previous line is a comment, copy indent, # and whitespace
     52         execute-keys -draft k x s^\h*#\h*<ret> yjP
     53     > catch %<
     54         # copy indent
     55         execute-keys -draft K <a-&>
     56         # indent after { [ ( |
     57         try %< execute-keys -draft k x <a-k>[[{(|]\h*$<ret> j <a-gt> >
     58     >
     59 >>
     60 
     61 define-command -hidden elvish-deindent %< evaluate-commands -draft -itersel %<
     62     try %<
     63         # Deindent only when there is a lone closing character
     64         execute-keys -draft x <a-k>^\h*[^\h]$<ret> <a-lt>
     65     >
     66 >>
     67 §