kakoune

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

scala.kak (3673B)


      1 # http://scala-lang.org
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](scala|sbt|sc) %{
      8     set-option buffer filetype scala
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=scala %[
     15     require-module scala
     16 
     17     hook window ModeChange pop:insert:.* -group scala-trim-indent scala-trim-indent
     18     hook window InsertChar \n -group scala-insert scala-insert-on-new-line
     19     hook window InsertChar \n -group scala-indent scala-indent-on-new-line
     20     hook window InsertChar \} -group scala-indent scala-indent-on-closing-curly-brace
     21 
     22     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window scala-.+ }
     23 ]
     24 
     25 hook -group scala-highlight global WinSetOption filetype=scala %{
     26     add-highlighter window/scala ref scala
     27     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scala }
     28 }
     29 
     30 
     31 provide-module scala %[
     32 
     33 # Highlighters
     34 # ‾‾‾‾‾‾‾‾‾‾‾‾
     35 
     36 add-highlighter shared/scala regions
     37 add-highlighter shared/scala/code default-region group
     38 add-highlighter shared/scala/string       region '"' (?<!\\)(\\\\)*"   fill string
     39 add-highlighter shared/scala/literal      region `    `                fill variable
     40 add-highlighter shared/scala/comment      region -recurse /[*] /[*] [*]/  fill comment
     41 add-highlighter shared/scala/line_comment region //   $                fill comment
     42 
     43 # Keywords are collected at
     44 # http://tutorialspoint.com/scala/scala_basic_syntax.htm
     45 
     46 add-highlighter shared/scala/code/ regex (?:\b|\W)(@\w+|import|package)\b 0:meta
     47 add-highlighter shared/scala/code/ regex \b(true|false|null)\b 0:value
     48 add-highlighter shared/scala/code/ regex \b(?:class|extends|with)\s+(\w+) 0:type
     49 add-highlighter shared/scala/code/ regex \b([A-Z]\w*)\b 0:type
     50 add-highlighter shared/scala/code/ regex (?:def|var|val)\s+(\w+) 0:variable
     51 add-highlighter shared/scala/code/ regex \b(become|case|catch|class|def|do|else|extends|final|finally|for|forSome|goto|if|initialize|macro|match|new|object|onTransition|return|startWith|stay|this|super|throw|trait|try|unbecome|using|val|var|when|while|with|yield)\b 0:keyword
     52 add-highlighter shared/scala/code/ regex \b(abstract|final|implicit|implicitly|lazy|override|private|protected|require|sealed)\b 0:attribute
     53 add-highlighter shared/scala/code/ regex (\[|\]|=>|<:|:>|=:=|::|&&|\|\|) 0:operator
     54 
     55 # Commands
     56 # ‾‾‾‾‾‾‾‾
     57 
     58 define-command -hidden scala-trim-indent %{
     59     # remove trailing white spaces
     60     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     61 }
     62 
     63 define-command -hidden scala-insert-on-new-line %[
     64     evaluate-commands -draft -itersel %[
     65         # copy // comments prefix and following white spaces
     66         try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K#\h* <ret> y<c-o>P<esc> }
     67     ]
     68 ]
     69 
     70 define-command -hidden scala-indent-on-new-line %[
     71     evaluate-commands -draft -itersel %[
     72         # preserve previous line indent
     73         try %[ execute-keys -draft <semicolon> K <a-&> ]
     74         # filter previous line
     75         try %[ execute-keys -draft k : scala-trim-indent <ret> ]
     76         # indent after lines ending with {
     77         try %[ execute-keys -draft k x <a-k> \{$ <ret> j <a-gt> ]
     78         # deindent closing brace when after cursor
     79         try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
     80     ]
     81 ]
     82 
     83 define-command -hidden scala-indent-on-closing-curly-brace %[
     84     evaluate-commands -draft -itersel %[
     85         # align to opening curly brace when alone on a line
     86         try %[ execute-keys -draft <a-h> <a-k> ^\h+\}$ <ret> m s \A|.\z <ret> 1<a-&> ]
     87     ]
     88 ]
     89 
     90 ]