2014-11-22 20:13:50 +01:00
|
|
|
hook global BufCreate .*\.java %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype java
|
2014-11-22 20:13:50 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=java %{
|
2019-03-13 19:15:59 +01:00
|
|
|
require-module java
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2021-09-24 17:38:55 +02:00
|
|
|
set-option window static_words %opt{java_static_words}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# cleanup trailing whitespaces when exiting insert mode
|
2022-03-16 23:20:07 +01:00
|
|
|
hook window ModeChange pop:insert:.* -group java-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group java-insert java-insert-on-new-line
|
2019-04-12 00:54:58 +02:00
|
|
|
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-.+ }
|
2019-03-13 19:15:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
hook -group java-highlight global WinSetOption filetype=java %{
|
|
|
|
add-highlighter window/java ref java
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java }
|
|
|
|
}
|
|
|
|
|
2019-04-13 21:57:57 +02:00
|
|
|
provide-module java %§
|
2019-03-13 19:15:59 +01:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/java regions
|
|
|
|
add-highlighter shared/java/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/java/string region %{(?<!')"} %{(?<!\\)(\\\\)*"} fill string
|
2021-05-17 21:15:30 +02:00
|
|
|
add-highlighter shared/java/character region %{'} %{(?<!\\)'} fill value
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/java/comment region /\* \*/ fill comment
|
2018-06-23 07:38:46 +02:00
|
|
|
add-highlighter shared/java/inline_documentation region /// $ fill documentation
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/java/line_comment region // $ fill comment
|
2014-11-22 20:13:50 +01:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/java/code/ regex "(?<!\w)@\w+\b" 0:meta
|
2014-11-22 20:13:50 +01:00
|
|
|
|
2017-01-13 21:35:14 +01:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden java-insert-on-new-line %[
|
|
|
|
# copy // comments prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
|
2021-04-17 10:17:01 +02:00
|
|
|
]
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden java-indent-on-new-line %~
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %=
|
2017-01-13 21:35:14 +01:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon>K<a-&> }
|
2017-01-13 21:35:14 +01:00
|
|
|
# indent after lines ending with { or (
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
2017-01-13 21:35:14 +01:00
|
|
|
# cleanup trailing white spaces on the previous line
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft kx s \h+$ <ret>d }
|
2017-01-13 21:35:14 +01:00
|
|
|
# align to opening paren of previous line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
|
2017-01-13 21:35:14 +01:00
|
|
|
# indent after a switch's case/default statements
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
|
2017-01-13 21:35:14 +01:00
|
|
|
# indent after keywords
|
2022-04-15 00:14:17 +02:00
|
|
|
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-,><a-gt> ]
|
2020-07-27 21:50:51 +02:00
|
|
|
# deindent closing brace(s) when after cursor
|
2022-03-16 23:20:07 +01:00
|
|
|
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
|
2017-01-13 21:35:14 +01:00
|
|
|
=
|
|
|
|
~
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden java-indent-on-opening-curly-brace %[
|
2017-01-13 21:35:14 +01:00
|
|
|
# align indent with opening paren when { is entered on a new line after the closing paren
|
2017-11-03 09:09:45 +01:00
|
|
|
try %[ execute-keys -draft -itersel h<a-F>)M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
|
2017-01-13 21:35:14 +01:00
|
|
|
]
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden java-indent-on-closing-curly-brace %[
|
2017-01-13 21:35:14 +01:00
|
|
|
# align to opening curly brace when alone on a line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %[ execute-keys -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\A|.\z<ret>1<a-&> ]
|
2017-01-13 21:35:14 +01:00
|
|
|
]
|
|
|
|
|
2021-09-24 17:38:55 +02:00
|
|
|
# Shell
|
|
|
|
# ‾‾‾‾‾
|
|
|
|
# Oracle 2021, 3.9 Keywords, Chapter 3. Lexical Structure, Java Language Specification, Java SE 17, viewed 25 September 2021, <https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.9>
|
|
|
|
#
|
|
|
|
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<space> 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"
|
|
|
|
# ---------------------------------------------------------------------------------------------- #
|
|
|
|
}
|
|
|
|
|
2019-04-13 21:57:57 +02:00
|
|
|
§
|