2014-11-22 22:13:50 +03:00
|
|
|
hook global BufCreate .*\.java %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype java
|
2014-11-22 22:13:50 +03:00
|
|
|
}
|
|
|
|
|
2019-03-13 21:15:59 +03:00
|
|
|
hook -once global BufSetOption filetype=java %{
|
|
|
|
require-module java
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module java %🦀
|
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/java regions
|
|
|
|
add-highlighter shared/java/code default-region group
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/java/string region %{(?<!')"} %{(?<!\\)(\\\\)*"} fill string
|
|
|
|
add-highlighter shared/java/comment region /\* \*/ fill comment
|
|
|
|
add-highlighter shared/java/line_comment region // $ fill comment
|
2014-11-22 22:13:50 +03:00
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/java/code/ regex %{\b(this|true|false|null)\b} 0:value
|
|
|
|
add-highlighter shared/java/code/ regex "\b(void|int|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 "(?<!\w)@\w+\b" 0:meta
|
2014-11-22 22:13:50 +03:00
|
|
|
|
2017-01-13 23:35:14 +03:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden java-indent-on-new-line %~
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %=
|
2017-01-13 23:35:14 +03:00
|
|
|
# preserve previous line indent
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft \;K<a-&> }
|
2017-01-13 23:35:14 +03:00
|
|
|
# indent after lines ending with { or (
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
2017-01-13 23:35:14 +03:00
|
|
|
# cleanup trailing white spaces on the previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
|
2017-01-13 23:35:14 +03:00
|
|
|
# align to opening paren of previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
|
2017-01-13 23:35:14 +03:00
|
|
|
# copy // comments prefix
|
2018-05-13 10:24:37 +03:00
|
|
|
try %{ execute-keys -draft \;<c-s>k<a-x> s ^\h*\K/{2,} <ret> y<c-o>P<esc> }
|
2017-01-13 23:35:14 +03:00
|
|
|
# indent after a switch's case/default statements
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
|
2017-01-13 23:35:14 +03:00
|
|
|
# indent after keywords
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -draft \;<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-space><a-gt> ]
|
2017-01-13 23:35:14 +03:00
|
|
|
=
|
|
|
|
~
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden java-indent-on-opening-curly-brace %[
|
2017-01-13 23:35:14 +03:00
|
|
|
# align indent with opening paren when { is entered on a new line after the closing paren
|
2017-11-03 11:09:45 +03: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 23:35:14 +03:00
|
|
|
]
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden java-indent-on-closing-curly-brace %[
|
2017-01-13 23:35:14 +03:00
|
|
|
# align to opening curly brace when alone on a line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %[ execute-keys -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\A|.\z<ret>1<a-&> ]
|
2017-01-13 23:35:14 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
2018-11-28 12:39:15 +03:00
|
|
|
|
|
|
|
hook -group java-highlight global WinSetOption filetype=java %{
|
|
|
|
add-highlighter window/java ref java
|
2018-12-11 02:11:35 +03:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/java }
|
2018-11-28 12:39:15 +03:00
|
|
|
}
|
|
|
|
|
2017-01-13 23:35:14 +03:00
|
|
|
hook global WinSetOption filetype=java %{
|
|
|
|
# cleanup trailing whitespaces when exiting insert mode
|
2018-12-19 12:10:26 +03:00
|
|
|
hook window ModeChange insert:.* -group java-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
|
2017-01-13 23:35:14 +03: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
|
|
|
|
|
2018-12-11 02:11:35 +03:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window java-.+ }
|
2017-01-13 23:35:14 +03:00
|
|
|
}
|
2019-03-13 21:15:59 +03:00
|
|
|
|
|
|
|
🦀
|