summaryrefslogtreecommitdiffstats
path: root/syntax/go.vim
diff options
context:
space:
mode:
Diffstat (limited to 'syntax/go.vim')
-rw-r--r--syntax/go.vim147
1 files changed, 25 insertions, 122 deletions
diff --git a/syntax/go.vim b/syntax/go.vim
index 0705c3ee..c02ad504 100644
--- a/syntax/go.vim
+++ b/syntax/go.vim
@@ -11,102 +11,6 @@ if exists("b:current_syntax")
finish
endif
-" Set settings to default values.
-if !exists("g:go_highlight_array_whitespace_error")
- let g:go_highlight_array_whitespace_error = 0
-endif
-
-if !exists("g:go_highlight_chan_whitespace_error")
- let g:go_highlight_chan_whitespace_error = 0
-endif
-
-if !exists("g:go_highlight_extra_types")
- let g:go_highlight_extra_types = 0
-endif
-
-if !exists("g:go_highlight_space_tab_error")
- let g:go_highlight_space_tab_error = 0
-endif
-
-if !exists("g:go_highlight_trailing_whitespace_error")
- let g:go_highlight_trailing_whitespace_error = 0
-endif
-
-if !exists("g:go_highlight_operators")
- let g:go_highlight_operators = 0
-endif
-
-if !exists("g:go_highlight_functions")
- let g:go_highlight_functions = 0
-endif
-
-if !exists("g:go_highlight_function_arguments")
- let g:go_highlight_function_arguments = 0
-endif
-
-if !exists("g:go_highlight_function_calls")
- let g:go_highlight_function_calls = 0
-endif
-
-if !exists("g:go_highlight_fields")
- let g:go_highlight_fields = 0
-endif
-
-if !exists("g:go_highlight_types")
- let g:go_highlight_types = 0
-endif
-
-if !exists("g:go_highlight_build_constraints")
- let g:go_highlight_build_constraints = 0
-endif
-
-if !exists("g:go_highlight_string_spellcheck")
- let g:go_highlight_string_spellcheck = 1
-endif
-
-if !exists("g:go_highlight_format_strings")
- let g:go_highlight_format_strings = 1
-endif
-
-if !exists("g:go_highlight_generate_tags")
- let g:go_highlight_generate_tags = 0
-endif
-
-if !exists("g:go_highlight_variable_assignments")
- let g:go_highlight_variable_assignments = 0
-endif
-
-if !exists("g:go_highlight_variable_declarations")
- let g:go_highlight_variable_declarations = 0
-endif
-
-let s:fold_block = 1
-let s:fold_import = 1
-let s:fold_varconst = 1
-let s:fold_package_comment = 1
-let s:fold_comment = 0
-
-if exists("g:go_fold_enable")
- " Enabled by default.
- if index(g:go_fold_enable, 'block') == -1
- let s:fold_block = 0
- endif
- if index(g:go_fold_enable, 'import') == -1
- let s:fold_import = 0
- endif
- if index(g:go_fold_enable, 'varconst') == -1
- let s:fold_varconst = 0
- endif
- if index(g:go_fold_enable, 'package_comment') == -1
- let s:fold_package_comment = 0
- endif
-
- " Disabled by default.
- if index(g:go_fold_enable, 'comment') > -1
- let s:fold_comment = 1
- endif
-endif
-
syn case match
syn keyword goPackage package
@@ -144,7 +48,6 @@ hi def link goUnsignedInts Type
hi def link goFloats Type
hi def link goComplexes Type
-
" Predefined functions and values
syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
@@ -160,7 +63,7 @@ syn keyword goTodo contained TODO FIXME XXX BUG
syn cluster goCommentGroup contains=goTodo
syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell
-if s:fold_comment
+if go#config#FoldEnable('comment')
syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell fold
syn match goComment "\v(^\s*//.*\n)+" contains=goGenerate,@goCommentGroup,@Spell fold
else
@@ -170,7 +73,7 @@ endif
hi def link goComment Comment
hi def link goTodo Todo
-if g:go_highlight_generate_tags != 0
+if go#config#HighlightGenerateTags()
syn match goGenerateVariables contained /\(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables
hi def link goGenerate PreProc
@@ -195,7 +98,7 @@ hi def link goEscapeError Error
" Strings and their contents
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
-if g:go_highlight_string_spellcheck != 0
+if go#config#HighlightStringSpellcheck()
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup,@Spell
syn region goRawString start=+`+ end=+`+ contains=@Spell
else
@@ -203,7 +106,7 @@ else
syn region goRawString start=+`+ end=+`+
endif
-if g:go_highlight_format_strings != 0
+if go#config#HighlightFormatStrings()
" [n] notation is valid for specifying explicit argument indexes
" 1. Match a literal % not preceded by a %.
" 2. Match any number of -, #, 0, space, or +
@@ -231,21 +134,21 @@ hi def link goCharacter Character
" Regions
syn region goParen start='(' end=')' transparent
-if s:fold_block
+if go#config#FoldEnable('block')
syn region goBlock start="{" end="}" transparent fold
else
syn region goBlock start="{" end="}" transparent
endif
" import
-if s:fold_import
+if go#config#FoldEnable('import')
syn region goImport start='import (' end=')' transparent fold contains=goImport,goString,goComment
else
syn region goImport start='import (' end=')' transparent contains=goImport,goString,goComment
endif
" var, const
-if s:fold_varconst
+if go#config#FoldEnable('varconst')
syn region goVar start='var (' end='^\s*)$' transparent fold
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments
syn region goConst start='const (' end='^\s*)$' transparent fold
@@ -288,12 +191,12 @@ hi def link goImaginary Number
hi def link goImaginaryFloat Float
" Spaces after "[]"
-if g:go_highlight_array_whitespace_error != 0
+if go#config#HighlightArrayWhitespaceError()
syn match goSpaceError display "\(\[\]\)\@<=\s\+"
endif
" Spacing errors around the 'chan' keyword
-if g:go_highlight_chan_whitespace_error != 0
+if go#config#HighlightChanWhitespaceError()
" receive-only annotation on chan type
"
" \(\<chan\>\)\@<!<- (only pick arrow when it doesn't come after a chan)
@@ -311,7 +214,7 @@ if g:go_highlight_chan_whitespace_error != 0
endif
" Extra types commonly seen
-if g:go_highlight_extra_types != 0
+if go#config#HighlightExtraTypes()
syn match goExtraType /\<bytes\.\(Buffer\)\>/
syn match goExtraType /\<io\.\(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
@@ -319,12 +222,12 @@ if g:go_highlight_extra_types != 0
endif
" Space-tab error
-if g:go_highlight_space_tab_error != 0
+if go#config#HighlightSpaceTabError()
syn match goSpaceError display " \+\t"me=e-1
endif
" Trailing white space error
-if g:go_highlight_trailing_whitespace_error != 0
+if go#config#HighlightTrailingWhitespaceError()
syn match goSpaceError display excludenl "\s\+$"
endif
@@ -342,7 +245,7 @@ hi def link goTodo Todo
syn match goVarArgs /\.\.\./
" Operators;
-if g:go_highlight_operators != 0
+if go#config#HighlightOperators()
" match single-char operators: - + % < > ! & | ^ * =
" and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= ==
syn match goOperator /[-+%<>!&|^*=]=\?/
@@ -361,13 +264,13 @@ endif
hi def link goOperator Operator
" Functions;
-if g:go_highlight_functions isnot 0 || g:go_highlight_function_arguments isnot 0
+if go#config#HighlightFunctions() || go#config#HighlightFunctionArguments()
syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleArguments skipwhite skipnl
syn match goReceiverVar /\w\+\ze\s\+\(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
syn match goFunction /\w\+/ nextgroup=goSimpleArguments contained skipwhite skipnl
syn match goReceiverType /\w\+/ contained
-if g:go_highlight_function_arguments isnot 0
+if go#config#HighlightFunctionArguments()
syn match goSimpleArguments /(\(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goArgumentName nextgroup=goSimpleArguments skipwhite skipnl
syn match goArgumentName /\w\+\(\s*,\s*\w\+\)*\ze\s\+\(\w\|\.\|\*\|\[\)/ contained nextgroup=goArgumentType skipwhite skipnl
syn match goArgumentType /\([^,)]\|\_s\)\+,\?/ contained nextgroup=goArgumentName skipwhite skipnl
@@ -382,19 +285,19 @@ endif
hi def link goFunction Function
" Function calls;
-if g:go_highlight_function_calls != 0
+if go#config#HighlightFunctionCalls()
syn match goFunctionCall /\w\+\ze(/ contains=goBuiltins,goDeclaration
endif
hi def link goFunctionCall Type
" Fields;
-if g:go_highlight_fields != 0
+if go#config#HighlightFields()
syn match goField /\.\w\+\([.\ \n\r\:\)\[,]\)\@=/hs=s+1
endif
hi def link goField Identifier
" Structs & Interfaces;
-if g:go_highlight_types != 0
+if go#config#HighlightTypes()
syn match goTypeConstructor /\<\w\+{\@=/
syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
@@ -410,19 +313,19 @@ hi def link goTypeDecl Keyword
hi def link goDeclType Keyword
" Variable Assignments
-if g:go_highlight_variable_assignments != 0
+if go#config#HighlightVariableAssignments()
syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/
hi def link goVarAssign Special
endif
" Variable Declarations
-if g:go_highlight_variable_declarations != 0
+if go#config#HighlightVariableDeclarations()
syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/
hi def link goVarDefs Special
endif
" Build Constraints
-if g:go_highlight_build_constraints != 0
+if go#config#HighlightBuildConstraints()
syn match goBuildKeyword display contained "+build"
" Highlight the known values of GOOS, GOARCH, and other +build options.
syn keyword goBuildDirectives contained
@@ -444,7 +347,7 @@ if g:go_highlight_build_constraints != 0
hi def link goBuildKeyword PreProc
endif
-if g:go_highlight_build_constraints != 0 || s:fold_package_comment
+if go#config#HighlightBuildConstraints() || go#config#FoldEnable('package_comment')
" One or more line comments that are followed immediately by a "package"
" declaration are treated like package documentation, so these must be
" matched as comments to avoid looking like working build constraints.
@@ -453,11 +356,11 @@ if g:go_highlight_build_constraints != 0 || s:fold_package_comment
exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/'
\ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
\ . ' contains=@goCommentGroup,@Spell'
- \ . (s:fold_package_comment ? ' fold' : '')
+ \ . (go#config#FoldEnable('package_comment') ? ' fold' : '')
exe 'syn region goPackageComment start=/\v\/\*.*\n(.*\n)*\s*\*\/\npackage/'
- \ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
+ \ . ' end=/\v\*\/\n\s*package/he=e-7,me=e-7,re=e-7'
\ . ' contains=@goCommentGroup,@Spell'
- \ . (s:fold_package_comment ? ' fold' : '')
+ \ . (go#config#FoldEnable('package_comment') ? ' fold' : '')
hi def link goPackageComment Comment
endif