diff --git a/rc/filetype/java.kak b/rc/filetype/java.kak index 1c187fc5..bad48834 100644 --- a/rc/filetype/java.kak +++ b/rc/filetype/java.kak @@ -8,6 +8,8 @@ hook global BufCreate .*\.java %{ hook global WinSetOption filetype=java %{ require-module java + set-option window static_words %opt{java_static_words} + # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group java-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } hook window InsertChar \n -group java-insert java-insert-on-new-line @@ -33,10 +35,6 @@ add-highlighter shared/java/comment region /\* \*/ fill comment add-highlighter shared/java/inline_documentation region /// $ fill documentation add-highlighter shared/java/line_comment region // $ fill comment -add-highlighter shared/java/code/ regex %{\b(this|true|false|null)\b} 0:value -add-highlighter shared/java/code/ regex "\b(void|byte|short|int|long|char|unsigned|float|boolean|double)\b" 0:type -add-highlighter shared/java/code/ regex "\b(while|for|if|else|do|static|switch|case|default|class|interface|enum|goto|break|continue|return|import|try|catch|throw|new|package|extends|implements|throws|instanceof)\b" 0:keyword -add-highlighter shared/java/code/ regex "\b(final|public|protected|private|abstract|synchronized|native|transient|volatile)\b" 0:attribute add-highlighter shared/java/code/ regex "(?^\h+\}$hms\A|.\z1 ] ] +# Shell +# ‾‾‾‾‾ +# Oracle 2021, 3.9 Keywords, Chapter 3. Lexical Structure, Java Language Specification, Java SE 17, viewed 25 September 2021, +# +evaluate-commands %sh{ + values='false null this true' + + types='boolean byte char double float int long short unsigned void' + + keywords='assert break case catch class continue default do else enum extends + finally for if implements import instanceof interface new package return + static strictfp super switch throw throws try var while yield' + + attributes='abstract final native non-sealed permits private protected public + record sealed synchronized transient volatile' + + modules='exports module open opens provides requires to transitive uses with' + + # ---------------------------------------------------------------------------------------------- # + join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } + # ---------------------------------------------------------------------------------------------- # + add_highlighter() { printf "add-highlighter shared/java/code/ regex %s %s\n" "$1" "$2"; } + # ---------------------------------------------------------------------------------------------- # + add_word_highlighter() { + + while [ $# -gt 0 ]; do + words=$1 face=$2; shift 2 + regex="\\b($(join "${words}" '|'))\\b" + add_highlighter "$regex" "1:$face" + done + + } + + # highlight: open not open() + add_module_highlighter() { + + while [ $# -gt 0 ]; do + words=$1 face=$2; shift 2 + regex="\\b($(join "${words}" '|'))\\b(?=\\s)" + add_highlighter "$regex" "1:$face" + done + + } + # ---------------------------------------------------------------------------------------------- # + printf %s\\n "declare-option str-list java_static_words $(join "${values} ${types} ${keywords} ${attributes} ${modules}" ' ')" + # ---------------------------------------------------------------------------------------------- # + add_word_highlighter "$values" "value" "$types" "type" "$keywords" "keyword" "$attributes" "attribute" + # ---------------------------------------------------------------------------------------------- # + add_module_highlighter "$modules" "module" + # ---------------------------------------------------------------------------------------------- # +} + §