# Adapted from the file created by Daniel Lewan TeddyDD hook global BufCreate "(.+\.(groovy|gvy|gy|gsh|gradle))|.+[Jj]enkinsfile.*" %{ set-option buffer filetype groovy } hook global WinSetOption filetype=groovy %{ require-module groovy set-option window static_words %opt{groovy_static_words} hook window ModeChange pop:insert:.* -group groovy-trim-indent %{ try %{ execute-keys -draft xs^\h+$d } } hook window InsertChar \n -group groovy-insert groovy-insert-on-new-line hook window InsertChar \n -group groovy-indent groovy-indent-on-new-line hook window InsertChar \{ -group groovy-indent groovy-indent-on-opening-curly-brace hook window InsertChar \} -group groovy-indent groovy-indent-on-closing-curly-brace hook -once -always window WinSetOption filetype=.* %{ remove-hooks window groovy-.+ } } hook -group groovy-highlight global WinSetOption filetype=groovy %{ add-highlighter window/groovy ref groovy hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/groovy } } provide-module groovy %§ add-highlighter shared/groovy regions add-highlighter shared/groovy/code default-region group add-highlighter shared/groovy/triple_quote region '"{3}' (?\w+)(?:\[.*?\])?\s+(\$?\w+)\s=" typ:type add-highlighter shared/groovy/code/numbers regex '\b[-+]?0x[A-Fa-f0-9_]+[.A-Fa-f0-9_p]*[lLiDgGIF]?|\b[-+]?[\d]+b?[.p_\dEe]*[lLiDgGIF]?' 0:value add-highlighter shared/groovy/slashy_string region "\b/\w" "(?kx s ^\h*\K/{2,}\h* yP } ] define-command -hidden groovy-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent try %{ execute-keys -draft K } # indent after lines ending with { or ( try %[ execute-keys -draft kx [{(]\h*$ j ] # cleanup trailing white spaces on the previous line try %{ execute-keys -draft kx s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # indent after a switch's case/default statements try %[ execute-keys -draft kx ^\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 ] # deindent closing brace(s) when after cursor try %[ execute-keys -draft x ^\h*[})] gh / [})] m 1 ] = ~ define-command -hidden groovy-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 groovy-indent-on-closing-curly-brace %[ # align to opening curly brace when alone on a line try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] ] §