# http://scala-lang.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](scala) %{ set-option buffer filetype scala } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ regions -default code scala \ string '"' (?|<:|:>|=:=|::|&&|\|\|) 0:operator # Commands # ‾‾‾‾‾‾‾‾ define-command -hidden scala-filter-around-selections %{ # remove trailing white spaces try %{ execute-keys -draft -itersel s \h+$ d } } define-command -hidden scala-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 : scala-filter-around-selections ] # indent after lines ending with { try %[ execute-keys -draft k \{$ j ] ] ] define-command -hidden scala-indent-on-closing-curly-brace %[ evaluate-commands -draft -itersel %[ # align to opening curly brace when alone on a line try %[ execute-keys -draft ^\h+\}$ m s \A|.\z 1 ] ] ] # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group scala-highlight global WinSetOption filetype=scala %{ add-highlighter window ref scala } hook global WinSetOption filetype=scala %[ hook window ModeChange insert:.* -group scala-hooks scala-filter-around-selections hook window InsertChar \n -group scala-indent scala-indent-on-new-line hook window InsertChar \} -group scala-indent scala-indent-on-closing-curly-brace ] hook -group scala-highlight global WinSetOption filetype=(?!scala).* %{ remove-highlighter window/scala } hook global WinSetOption filetype=(?!scala).* %{ remove-hooks window scala-indent remove-hooks window scala-hooks }