2015-07-21 10:22:57 +02:00
|
|
|
# https://golang.org/
|
|
|
|
#
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2015-09-04 13:51:36 +02:00
|
|
|
hook global BufCreate .*\.go %{
|
|
|
|
set buffer mimetype ""
|
2015-07-21 10:22:57 +02:00
|
|
|
set buffer filetype golang
|
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
addhl -group / regions -default code golang \
|
|
|
|
back_string '`' '`' '' \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
single_string "'" (?<!\\)(\\\\)*' '' \
|
2015-10-21 07:03:33 +02:00
|
|
|
comment /\* \*/ '' \
|
2015-07-21 10:22:57 +02:00
|
|
|
comment '//' $ ''
|
|
|
|
|
|
|
|
addhl -group /golang/back_string fill string
|
|
|
|
addhl -group /golang/double_string fill string
|
|
|
|
addhl -group /golang/single_string fill string
|
|
|
|
addhl -group /golang/comment fill comment
|
|
|
|
|
2015-09-04 13:51:36 +02:00
|
|
|
addhl -group /golang/code regex %{-?([0-9]*\.(?!0[xX]))?\<([0-9]+|0[xX][0-9a-fA-F]+)\.?([eE][+-]?[0-9]+)?i?\>} 0:value
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
%sh{
|
|
|
|
# Grammar
|
2016-03-14 17:29:11 +01:00
|
|
|
keywords="break|default|defer|else|fallthrough|for|func|go|goto|if|import"
|
|
|
|
keywords="${keywords}|interface|make|new|package|range|return|select|case|switch|type|continue"
|
2016-03-14 13:08:51 +01:00
|
|
|
attributes="const"
|
2016-03-14 17:29:11 +01:00
|
|
|
types="bool|byte|chan|complex128|complex64|float32|float64|int|int16|int32"
|
|
|
|
types="${types}|int64|int8|interface|intptr|map|rune|string|struct|uint|uint16|uint32|uint64|uint8"
|
|
|
|
values="false|true|nil"
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
2016-03-17 14:30:14 +01:00
|
|
|
printf %s "hook global WinSetOption filetype=golang %{
|
2016-04-09 11:20:13 +02:00
|
|
|
set window static_words '${keywords}:${attributes}:${types}:${values}'
|
2016-03-17 14:30:14 +01:00
|
|
|
}" | sed 's,|,:,g'
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
# Highlight keywords
|
2016-03-17 14:30:14 +01:00
|
|
|
printf %s "
|
2016-03-14 17:29:11 +01:00
|
|
|
addhl -group /golang/code regex \<(${keywords})\> 0:keyword
|
|
|
|
addhl -group /golang/code regex \<(${attributes})\> 0:attribute
|
|
|
|
addhl -group /golang/code regex \<(${types})\> 0:type
|
|
|
|
addhl -group /golang/code regex \<(${values})\> 0:value
|
2016-03-14 13:08:51 +01:00
|
|
|
"
|
|
|
|
}
|
2015-07-21 10:22:57 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
def -hidden _golang-indent-on-new-line %~
|
|
|
|
eval -draft -itersel %=
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft \;K<a-&> }
|
|
|
|
# indent after lines ending with { or (
|
|
|
|
try %[ exec -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
|
|
|
# cleanup trailing white spaces on the previous line
|
|
|
|
try %{ exec -draft k<a-x> s \h+$ <ret>d }
|
|
|
|
# align to opening paren of previous line
|
|
|
|
try %{ exec -draft [( <a-k> \`\([^\n]+\n[^\n]*\n?\' <ret> s \`\(\h*.|.\' <ret> '<a-;>' & }
|
|
|
|
# copy // comments prefix
|
|
|
|
try %{ exec -draft \;<c-s>k<a-x> s ^\h*\K/{2,} <ret> y<c-o><c-o>P<esc> }
|
|
|
|
# indent after a switch's case/default statements
|
|
|
|
try %[ exec -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
|
|
|
|
# indent after if|else|while|for
|
|
|
|
try %[ exec -draft \;<a-F>)MB <a-k> \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' <ret> s \`|.\' <ret> 1<a-&>1<a-space><a-gt> ]
|
|
|
|
=
|
|
|
|
~
|
|
|
|
|
|
|
|
def -hidden _golang-indent-on-opening-curly-brace %[
|
|
|
|
# align indent with opening paren when { is entered on a new line after the closing paren
|
|
|
|
try %[ exec -draft -itersel h<a-F>)M <a-k> \`\(.*\)\h*\n\h*\{\' <ret> s \`|.\' <ret> 1<a-&> ]
|
|
|
|
]
|
|
|
|
|
|
|
|
def -hidden _golang-indent-on-closing-curly-brace %[
|
|
|
|
# align to opening curly brace when alone on a line
|
|
|
|
try %[ exec -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\`|.\'<ret>1<a-&> ]
|
|
|
|
]
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=golang %{
|
|
|
|
addhl ref golang
|
|
|
|
|
|
|
|
# cleanup trailing whitespaces when exiting insert mode
|
|
|
|
hook window InsertEnd .* -group golang-hooks %{ try %{ exec -draft <a-x>s^\h+$<ret>d } }
|
|
|
|
hook window InsertChar \n -group golang-indent _golang-indent-on-new-line
|
|
|
|
hook window InsertChar \{ -group golang-indent _golang-indent-on-opening-curly-brace
|
|
|
|
hook window InsertChar \} -group golang-indent _golang-indent-on-closing-curly-brace
|
2015-09-06 17:14:17 +02:00
|
|
|
|
2015-10-22 15:41:19 +02:00
|
|
|
set window formatcmd "gofmt"
|
2015-07-21 10:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!golang).* %{
|
|
|
|
rmhl golang
|
2015-09-06 17:14:17 +02:00
|
|
|
|
2015-07-22 11:02:10 +02:00
|
|
|
rmhooks window golang-hooks
|
|
|
|
rmhooks window golang-indent
|
2015-07-21 10:22:57 +02:00
|
|
|
}
|