kakoune

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

janet.kak (3404B)


      1 # http://janet-lang.org
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](janet|jdn) %{
      8     set-option buffer filetype janet
      9 }
     10 
     11 
     12 hook global WinSetOption filetype=janet %{
     13     require-module janet
     14 
     15     hook window ModeChange pop:insert:.* -group janet-trim-indent janet-trim-indent
     16     hook window InsertChar \n -group janet-indent janet-indent-on-new-line
     17     set-option buffer extra_word_chars ! @ $ '%' ^ & * - _ + = : < > . ?
     18 
     19     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window janet-.+ }
     20 }
     21 
     22 hook -group janet-highlight global WinSetOption filetype=janet %{
     23     add-highlighter window/janet ref janet
     24     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/janet }
     25 }
     26 
     27 provide-module janet %{
     28 
     29 require-module lisp
     30 
     31 # Highlighters
     32 # ‾‾‾‾‾‾‾‾‾‾‾‾
     33 
     34 add-highlighter shared/janet regions
     35 add-highlighter shared/janet/code default-region group
     36 add-highlighter shared/janet/comment region '(?<!\\)(?:\\\\)*\K#' '$' fill comment
     37 add-highlighter shared/janet/comment-form region -recurse \( '(?<!\\)(?:\\\\)*\K\(comment ' '\)' fill comment
     38 add-highlighter shared/janet/string region '(?<!\\)(?:\\\\)*\K"' '(?<!\\)(?:\\\\)*"' fill string
     39 add-highlighter shared/janet/raw-string region -match-capture '(`+)' '(`+)' fill string
     40 add-highlighter shared/janet/code/ regex \b(nil|true|false)\b 0:value
     41 add-highlighter shared/janet/code/number regex \W\K(?:[\-+]?\dx?[\der._+a-f]*)\b 0:value
     42 add-highlighter shared/janet/code/function-definition regex \((?:defn-?|fn)\s([!@$%\^&*\-_+=:<>.?\w/]+) 1:function
     43 add-highlighter shared/janet/code/function-call regex \(([!@$%\^&*\-_+=:<>.?\w/]+) 1:function
     44 add-highlighter shared/janet/code/keyword regex \W\K:[!@$%\^&*\-_+=:<>.?\w/]+ 0:value
     45 add-highlighter shared/janet/code/special regex \((def-?|defn-?|var-?|fn|do|quote|if|splice|while|break|set|quasiquote|unquote|upscope)\s 1:keyword
     46 add-highlighter shared/janet/code/ regex \W\K(&|&opt|&keys|&named)\W 1:keyword
     47 
     48 # Commands
     49 # ‾‾‾‾‾‾‾‾
     50 
     51 define-command -hidden janet-trim-indent lisp-trim-indent
     52 
     53 declare-option \
     54     -docstring 'regex matching the head of forms which have options *and* indented bodies' \
     55     regex janet_special_indent_forms \
     56     '(?:def.*|while|for|fn\*?|if(-.*|)|let.*|loop|seq|with(-.*|)|when(-.*|))|defer|do|match|var'
     57 
     58 define-command -hidden janet-indent-on-new-line %{
     59     # registers: i = best align point so far; w = start of first word of form
     60     evaluate-commands -draft -save-regs '/"|^@iw' -itersel %{
     61         execute-keys -draft 'gk"iZ'
     62         try %{
     63             execute-keys -draft '[bl"i<a-Z><gt>"wZ'
     64 
     65             try %{
     66                 # If a special form, indent another j
     67                 execute-keys -draft '"wze<a-k>\A' %opt{janet_special_indent_forms} '\z<ret><a-L>s.\K.*<ret><a-;>;"i<a-Z><gt>'
     68             } catch %{
     69                 # If not special and parameter appears on line 1, indent to parameter
     70                 execute-keys -draft '"wze<a-l>s\h\K[^\s].*<ret><a-;>;"i<a-Z><gt>'
     71             }
     72         }
     73         try %{ execute-keys -draft '[rl"i<a-Z><gt>' }
     74         try %{ execute-keys -draft '[Bl"i<a-Z><gt>' }
     75         execute-keys -draft ';"i<a-z>a&,'
     76         # trim trailing whitespace on the previous line
     77         try %{ execute-keys -draft k : janet-trim-indent <ret> }
     78     }
     79 }
     80 
     81 }