summaryrefslogtreecommitdiff
path: root/misc/vim
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-04-06 15:14:11 +0200
committerOndřej Surý <ondrej@sury.org>2012-04-06 15:14:11 +0200
commit505c19580e0f43fe5224431459cacb7c21edd93d (patch)
tree79e2634c253d60afc0cc0b2f510dc7dcbb48497b /misc/vim
parent1336a7c91e596c423a49d1194ea42d98bca0d958 (diff)
downloadgolang-505c19580e0f43fe5224431459cacb7c21edd93d.tar.gz
Imported Upstream version 1upstream/1
Diffstat (limited to 'misc/vim')
-rw-r--r--misc/vim/ftdetect/gofiletype.vim24
-rw-r--r--misc/vim/ftplugin/go/fmt.vim22
-rw-r--r--misc/vim/syntax/go.vim9
3 files changed, 45 insertions, 10 deletions
diff --git a/misc/vim/ftdetect/gofiletype.vim b/misc/vim/ftdetect/gofiletype.vim
index f03a1d8dc..b658f6b0e 100644
--- a/misc/vim/ftdetect/gofiletype.vim
+++ b/misc/vim/ftdetect/gofiletype.vim
@@ -1 +1,23 @@
-au BufReadPre,BufNewFile *.go set filetype=go fileencoding=utf-8 fileencodings=utf-8
+" We take care to preserve the user's fileencodings and fileformats,
+" because those settings are global (not buffer local), yet we want
+" to override them for loading Go files, which are defined to be UTF-8.
+let s:current_fileformats = ''
+let s:current_fileencodings = ''
+
+" define fileencodings to open as utf-8 encoding even if it's ascii.
+function! s:gofiletype_pre()
+ let s:current_fileformats = &g:fileformats
+ let s:current_fileencodings = &g:fileencodings
+ set fileencodings=utf-8 fileformats=unix
+ setlocal filetype=go
+endfunction
+
+" restore fileencodings as others
+function! s:gofiletype_post()
+ let &g:fileformats = s:current_fileformats
+ let &g:fileencodings = s:current_fileencodings
+endfunction
+
+au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
+au BufRead *.go call s:gofiletype_pre()
+au BufReadPost *.go call s:gofiletype_post()
diff --git a/misc/vim/ftplugin/go/fmt.vim b/misc/vim/ftplugin/go/fmt.vim
index a299dfcee..0ee44cd59 100644
--- a/misc/vim/ftplugin/go/fmt.vim
+++ b/misc/vim/ftplugin/go/fmt.vim
@@ -17,12 +17,26 @@ command! -buffer Fmt call s:GoFormat()
function! s:GoFormat()
let view = winsaveview()
- %!gofmt
+ silent %!gofmt
if v:shell_error
- %| " output errors returned by gofmt
- " TODO(dchest): perhaps, errors should go to quickfix
+ let errors = []
+ for line in getline(1, line('$'))
+ let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
+ if !empty(tokens)
+ call add(errors, {"filename": @%,
+ \"lnum": tokens[2],
+ \"col": tokens[3],
+ \"text": tokens[4]})
+ endif
+ endfor
+ if empty(errors)
+ % | " Couldn't detect gofmt error format, output errors
+ endif
undo
- echohl Error | echomsg "Gofmt returned error" | echohl None
+ if !empty(errors)
+ call setloclist(0, errors, 'r')
+ endif
+ echohl Error | echomsg "Gofmt returned error" | echohl None
endif
call winrestview(view)
endfunction
diff --git a/misc/vim/syntax/go.vim b/misc/vim/syntax/go.vim
index 26d7defe3..1ce6cb27f 100644
--- a/misc/vim/syntax/go.vim
+++ b/misc/vim/syntax/go.vim
@@ -18,7 +18,7 @@
" Highlights white space around the communications operator that don't follow
" the standard style.
" - go_highlight_extra_types
-" Highlights commonly used library types (os.Error, etc.).
+" Highlights commonly used library types (io.Reader, etc.).
" - go_highlight_space_tab_error
" Highlights instances of tabs following spaces.
" - go_highlight_trailing_whitespace_error
@@ -67,8 +67,8 @@ hi def link goLabel Label
hi def link goRepeat Repeat
" Predefined types
-syn keyword goType chan map bool string
-syn keyword goSignedInts int int8 int16 int32 int64
+syn keyword goType chan map bool string error
+syn keyword goSignedInts int int8 int16 int32 int64 rune
syn keyword goUnsignedInts byte uint uint8 uint16 uint32 uint64 uintptr
syn keyword goFloats float32 float64
syn keyword goComplexes complex64 complex128
@@ -85,7 +85,7 @@ syn match goType /\<func\>/
syn match goDeclaration /^func\>/
" Predefined functions and values
-syn keyword goBuiltins append cap close complex copy imag len
+syn keyword goBuiltins append cap close complex copy delete imag len
syn keyword goBuiltins make new panic print println real recover
syn keyword goConstants iota true false nil
@@ -180,7 +180,6 @@ endif
if go_highlight_extra_types != 0
syn match goExtraType /\<bytes\.\(Buffer\)\>/
syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/
- syn match goExtraType /\<\(os\.Error\)\>/
syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
syn match goExtraType /\<unsafe\.Pointer\>/
endif