From c0dccdd90dd615cf663d95fd94fbdbdf2a88b165 Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Mon, 18 Mar 2019 19:56:34 +0100 Subject: Add categories in rc/ Closes #2783 --- rc/filetype/java.kak | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 rc/filetype/java.kak (limited to 'rc/filetype/java.kak') diff --git a/rc/filetype/java.kak b/rc/filetype/java.kak new file mode 100644 index 00000000..7caa5aee --- /dev/null +++ b/rc/filetype/java.kak @@ -0,0 +1,65 @@ +hook global BufCreate .*\.java %{ + set-option buffer filetype java +} + +add-highlighter shared/java regions +add-highlighter shared/java/code default-region group +add-highlighter shared/java/string region %{(? } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # align to opening paren of previous line + try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # copy // comments prefix + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after keywords + try %[ execute-keys -draft \;)MB \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] + = +~ + +define-command -hidden java-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] +] + +define-command -hidden java-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group java-highlight global WinSetOption filetype=java %{ + add-highlighter window/java ref java + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java } +} + +hook global WinSetOption filetype=java %{ + # cleanup trailing whitespaces when exiting insert mode + hook window ModeChange insert:.* -group java-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group java-indent java-indent-on-new-line + hook window InsertChar \{ -group java-indent java-indent-on-opening-curly-brace + hook window InsertChar \} -group java-indent java-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window java-.+ } +} -- cgit v1.2.3