From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/scala.kak | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 autoload/filetype/scala.kak (limited to 'autoload/filetype/scala.kak') diff --git a/autoload/filetype/scala.kak b/autoload/filetype/scala.kak new file mode 100644 index 0000000..05d7b28 --- /dev/null +++ b/autoload/filetype/scala.kak @@ -0,0 +1,90 @@ +# http://scala-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](scala|sbt|sc) %{ + set-option buffer filetype scala +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=scala %[ + require-module scala + + hook window ModeChange pop:insert:.* -group scala-trim-indent scala-trim-indent + hook window InsertChar \n -group scala-insert scala-insert-on-new-line + 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 -once -always window WinSetOption filetype=.* %{ remove-hooks window scala-.+ } +] + +hook -group scala-highlight global WinSetOption filetype=scala %{ + add-highlighter window/scala ref scala + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/scala } +} + + +provide-module scala %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/scala regions +add-highlighter shared/scala/code default-region group +add-highlighter shared/scala/string region '"' (?|<:|:>|=:=|::|&&|\|\|) 0:operator + +# Commands +# ‾‾‾‾‾‾‾‾ + +define-command -hidden scala-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel x s \h+$ d } +} + +define-command -hidden scala-insert-on-new-line %[ + evaluate-commands -draft -itersel %[ + # copy // comments prefix and following white spaces + try %{ execute-keys -draft kx s ^\h*\K#\h* yP } + ] +] + +define-command -hidden scala-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # preserve previous line indent + try %[ execute-keys -draft K ] + # filter previous line + try %[ execute-keys -draft k : scala-trim-indent ] + # indent after lines ending with { + try %[ execute-keys -draft k x \{$ j ] + # deindent closing brace when after cursor + try %[ execute-keys -draft x ^\h*\} gh / \} m 1 ] + ] +] + +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 ] + ] +] + +] -- cgit v1.2.3