diff --git a/.vim/bundle/go-official/autoload/go/complete.vim b/.vim/bundle/go-official/autoload/go/complete.vim new file mode 100644 index 0000000..d4ae3b9 --- /dev/null +++ b/.vim/bundle/go-official/autoload/go/complete.vim @@ -0,0 +1,49 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" This file provides a utility function that performs auto-completion of +" package names, for use by other commands. + +let s:goos = $GOOS +let s:goarch = $GOARCH + +if len(s:goos) == 0 + if exists('g:golang_goos') + let s:goos = g:golang_goos + elseif has('win32') || has('win64') + let s:goos = 'windows' + elseif has('macunix') + let s:goos = 'darwin' + else + let s:goos = '*' + endif +endif + +if len(s:goarch) == 0 + if exists('g:golang_goarch') + let s:goarch = g:golang_goarch + else + let s:goarch = '*' + endif +endif + +function! go#complete#Package(ArgLead, CmdLine, CursorPos) + let goroot = $GOROOT + if len(goroot) == 0 + " should not occur. + return [] + endif + let ret = {} + let root = expand(goroot.'/pkg/'.s:goos.'_'.s:goarch) + for i in split(globpath(root, a:ArgLead.'*'), "\n") + if isdirectory(i) + let i .= '/' + elseif i !~ '\.a$' + continue + endif + let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g') + let ret[i] = i + endfor + return sort(keys(ret)) +endfunction diff --git a/.vim/bundle/go-official/ftdetect/gofiletype.vim b/.vim/bundle/go-official/ftdetect/gofiletype.vim new file mode 100644 index 0000000..f03a1d8 --- /dev/null +++ b/.vim/bundle/go-official/ftdetect/gofiletype.vim @@ -0,0 +1 @@ +au BufReadPre,BufNewFile *.go set filetype=go fileencoding=utf-8 fileencodings=utf-8 diff --git a/.vim/bundle/go-official/ftplugin/go/fmt.vim b/.vim/bundle/go-official/ftplugin/go/fmt.vim new file mode 100644 index 0000000..0ee44cd --- /dev/null +++ b/.vim/bundle/go-official/ftplugin/go/fmt.vim @@ -0,0 +1,44 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" fmt.vim: Vim command to format Go files with gofmt. +" +" This filetype plugin add a new commands for go buffers: +" +" :Fmt +" +" Filter the current Go buffer through gofmt. +" It tries to preserve cursor position and avoids +" replacing the buffer with stderr output. +" + +command! -buffer Fmt call s:GoFormat() + +function! s:GoFormat() + let view = winsaveview() + silent %!gofmt + if v:shell_error + 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 + if !empty(errors) + call setloclist(0, errors, 'r') + endif + echohl Error | echomsg "Gofmt returned error" | echohl None + endif + call winrestview(view) +endfunction + +" vim:ts=4:sw=4:et diff --git a/.vim/bundle/go-official/ftplugin/go/godoc.vim b/.vim/bundle/go-official/ftplugin/go/godoc.vim new file mode 100644 index 0000000..55195a6 --- /dev/null +++ b/.vim/bundle/go-official/ftplugin/go/godoc.vim @@ -0,0 +1,13 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" godoc.vim: Vim command to see godoc. + +if exists("b:did_ftplugin") + finish +endif + +silent! nmap K (godoc-keyword) + +" vim:ts=4:sw=4:et diff --git a/.vim/ftplugin/go/import.vim b/.vim/bundle/go-official/ftplugin/go/import.vim similarity index 94% rename from .vim/ftplugin/go/import.vim rename to .vim/bundle/go-official/ftplugin/go/import.vim index b5814ca..6705a47 100644 --- a/.vim/ftplugin/go/import.vim +++ b/.vim/bundle/go-official/ftplugin/go/import.vim @@ -36,9 +36,9 @@ if exists("b:did_ftplugin") finish endif -command! -buffer -nargs=? Drop call s:SwitchImport(0, '', ) -command! -buffer -nargs=1 Import call s:SwitchImport(1, '', ) -command! -buffer -nargs=* ImportAs call s:SwitchImport(1, ) +command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', ) +command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', ) +command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, ) map f :Import fmt map F :Drop fmt diff --git a/.vim/bundle/go-official/indent/go.vim b/.vim/bundle/go-official/indent/go.vim new file mode 100644 index 0000000..faf4d79 --- /dev/null +++ b/.vim/bundle/go-official/indent/go.vim @@ -0,0 +1,65 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" indent/go.vim: Vim indent file for Go. +" +" TODO: +" - function invocations split across lines +" - general line splits (line ends in an operator) + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" C indentation is too far off useful, mainly due to Go's := operator. +" Let's just define our own. +setlocal nolisp +setlocal autoindent +setlocal indentexpr=GoIndent(v:lnum) +setlocal indentkeys+=<:>,0=},0=) + +if exists("*GoIndent") + finish +endif + +function! GoIndent(lnum) + let prevlnum = prevnonblank(a:lnum-1) + if prevlnum == 0 + " top of file + return 0 + endif + + " grab the previous and current line, stripping comments. + let prevl = substitute(getline(prevlnum), '//.*$', '', '') + let thisl = substitute(getline(a:lnum), '//.*$', '', '') + let previ = indent(prevlnum) + + let ind = previ + + if prevl =~ '[({]\s*$' + " previous line opened a block + let ind += &sw + endif + if prevl =~# '^\s*\(case .*\|default\):$' + " previous line is part of a switch statement + let ind += &sw + endif + " TODO: handle if the previous line is a label. + + if thisl =~ '^\s*[)}]' + " this line closed a block + let ind -= &sw + endif + + " Colons are tricky. + " We want to outdent if it's part of a switch ("case foo:" or "default:"). + " We ignore trying to deal with jump labels because (a) they're rare, and + " (b) they're hard to disambiguate from a composite literal key. + if thisl =~# '^\s*\(case .*\|default\):$' + let ind -= &sw + endif + + return ind +endfunction diff --git a/.vim/bundle/go-official/plugin/godoc.vim b/.vim/bundle/go-official/plugin/godoc.vim new file mode 100644 index 0000000..fdb4966 --- /dev/null +++ b/.vim/bundle/go-official/plugin/godoc.vim @@ -0,0 +1,85 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" godoc.vim: Vim command to see godoc. + +if exists("g:loaded_godoc") + finish +endif +let g:loaded_godoc = 1 + +let s:buf_nr = -1 +let s:last_word = '' + +function! s:GodocView() + if !bufexists(s:buf_nr) + leftabove new + file `="[Godoc]"` + let s:buf_nr = bufnr('%') + elseif bufwinnr(s:buf_nr) == -1 + leftabove split + execute s:buf_nr . 'buffer' + delete _ + elseif bufwinnr(s:buf_nr) != bufwinnr('%') + execute bufwinnr(s:buf_nr) . 'wincmd w' + endif + + setlocal filetype=godoc + setlocal bufhidden=delete + setlocal buftype=nofile + setlocal noswapfile + setlocal nobuflisted + setlocal modifiable + setlocal nocursorline + setlocal nocursorcolumn + setlocal iskeyword+=: + setlocal iskeyword-=- + + nnoremap K :Godoc + + au BufHidden call let buf_nr = -1 +endfunction + +function! s:GodocWord(word) + let word = a:word + silent! let content = system('godoc ' . word) + if v:shell_error || !len(content) + if len(s:last_word) + silent! let content = system('godoc ' . s:last_word.'/'.word) + if v:shell_error || !len(content) + echo 'No documentation found for "' . word . '".' + return + endif + let word = s:last_word.'/'.word + else + echo 'No documentation found for "' . word . '".' + return + endif + endif + let s:last_word = word + silent! call s:GodocView() + setlocal modifiable + silent! %d _ + silent! put! =content + silent! normal gg + setlocal nomodifiable + setfiletype godoc +endfunction + +function! s:Godoc(...) + let word = join(a:000, ' ') + if !len(word) + let word = expand('') + endif + let word = substitute(word, '[^a-zA-Z0-9\/]', '', 'g') + if !len(word) + return + endif + call s:GodocWord(word) +endfunction + +command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc() +nnoremap (godoc-keyword) :call Godoc('') + +" vim:ts=4:sw=4:et diff --git a/.vim/bundle/go-official/readme.txt b/.vim/bundle/go-official/readme.txt new file mode 100644 index 0000000..fe15da9 --- /dev/null +++ b/.vim/bundle/go-official/readme.txt @@ -0,0 +1,76 @@ +Vim plugins for Go (http://golang.org) +====================================== + +To use all the Vim plugins, add these lines to your vimrc. + + set rtp+=$GOROOT/misc/vim + filetype plugin indent on + syntax on + +If you want to select fewer plugins, use the instructions in the rest of +this file. + +Vim syntax highlighting +----------------------- + +To install automatic syntax highlighting for GO programs: + + 1. Copy or link the filetype detection script to the ftdetect directory + underneath your vim runtime directory (normally $HOME/.vim/ftdetect) + 2. Copy or link syntax/go.vim to the syntax directory underneath your vim + runtime directory (normally $HOME/.vim/syntax). Linking this file rather + than just copying it will ensure any changes are automatically reflected + in your syntax highlighting. + 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): + + syntax on + +In a typical unix environment you might accomplish this using the following +commands: + + mkdir -p $HOME/.vim/ftdetect + mkdir -p $HOME/.vim/syntax + mkdir -p $HOME/.vim/autoload/go + ln -s $GOROOT/misc/vim/ftdetect/gofiletype.vim $HOME/.vim/ftdetect/ + ln -s $GOROOT/misc/vim/syntax/go.vim $HOME/.vim/syntax + ln -s $GOROOT/misc/vim/autoload/go/complete.vim $HOME/.vim/autoload/go + echo "syntax on" >> $HOME/.vimrc + + +Vim filetype plugins +-------------------- + +To install one of the available filetype plugins: + + 1. Same as 1 above. + 2. Copy or link one or more plugins from ftplugin/go/*.vim to the + Go-specific ftplugin directory underneath your vim runtime directory + (normally $HOME/.vim/ftplugin/go/*.vim). + 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): + + filetype plugin on + + +Vim indentation plugin +---------------------- + +To install automatic indentation: + + 1. Same as 1 above. + 2. Copy or link indent/go.vim to the indent directory underneath your vim + runtime directory (normally $HOME/.vim/indent). + 3. Add the following line to your .vimrc file (normally $HOME/.vimrc): + + filetype indent on + + +Godoc plugin +------------ + +To install godoc plugin: + + 1. Same as 1 above. + 2. Copy or link plugin/godoc.vim to $HOME/.vim/plugin/godoc, + syntax/godoc.vim to $HOME/.vim/syntax/godoc.vim, + ftplugin/go/godoc.vim to $HOME/.vim/ftplugin/go/godoc.vim. + and autoload/go/complete.vim to $HOME/.vim/autoload/go/complete.vim. diff --git a/.vim/syntax/go.vim b/.vim/bundle/go-official/syntax/go.vim similarity index 97% rename from .vim/syntax/go.vim rename to .vim/bundle/go-official/syntax/go.vim index 26d7def..1ce6cb2 100644 --- a/.vim/syntax/go.vim +++ b/.vim/bundle/go-official/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 /\/ 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 /\/ syn match goExtraType /\/ - syn match goExtraType /\<\(os\.Error\)\>/ syn match goExtraType /\/ syn match goExtraType /\/ endif diff --git a/.vim/bundle/go-official/syntax/godoc.vim b/.vim/bundle/go-official/syntax/godoc.vim new file mode 100644 index 0000000..82f78aa --- /dev/null +++ b/.vim/bundle/go-official/syntax/godoc.vim @@ -0,0 +1,20 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. + +if exists("b:current_syntax") + finish +endif + +syn case match +syn match godocTitle "^\([A-Z]*\)$" + +command -nargs=+ HiLink hi def link + +HiLink godocTitle Title + +delcommand HiLink + +let b:current_syntax = "godoc" + +" vim:ts=4 sts=2 sw=2: diff --git a/.vim/ftdetect/gofiletype.vim b/.vim/ftdetect/gofiletype.vim deleted file mode 100644 index 8843121..0000000 --- a/.vim/ftdetect/gofiletype.vim +++ /dev/null @@ -1 +0,0 @@ -au BufRead,BufNewFile *.go set filetype=go diff --git a/.vim/ftplugin/go/fmt.vim b/.vim/ftplugin/go/fmt.vim deleted file mode 100644 index 18a2156..0000000 --- a/.vim/ftplugin/go/fmt.vim +++ /dev/null @@ -1,30 +0,0 @@ -" Copyright 2011 The Go Authors. All rights reserved. -" Use of this source code is governed by a BSD-style -" license that can be found in the LICENSE file. -" -" fmt.vim: Vim command to format Go files with gofmt. -" -" This filetype plugin add a new commands for go buffers: -" -" :Fmt -" -" Filter the current Go buffer through gofmt. -" It tries to preserve cursor position and avoids -" replacing the buffer with stderr output. -" - -command! Fmt call s:GoFormat() - -function! s:GoFormat() - let view = winsaveview() - %!gofmt - if v:shell_error - %| " output errors returned by gofmt - " TODO(dchest): perhaps, errors should go to quickfix - undo - echohl Error | echomsg "Gofmt returned error" | echohl None - endif - call winrestview(view) -endfunction - -" vim:ts=4:sw=4:et diff --git a/.vim/indent/go.vim b/.vim/indent/go.vim deleted file mode 100644 index 2e9f191..0000000 --- a/.vim/indent/go.vim +++ /dev/null @@ -1,30 +0,0 @@ -" Copyright 2011 The Go Authors. All rights reserved. -" Use of this source code is governed by a BSD-style -" license that can be found in the LICENSE file. -" -" indent/go.vim: Vim indent file for Go. -" - -if exists("b:did_indent") - finish -endif -let b:did_indent = 1 - -" C indentation is mostly correct -setlocal cindent - -" Options set: -" +0 -- Don't indent continuation lines (because Go doesn't use semicolons -" much) -" L0 -- Don't move jump labels (NOTE: this isn't correct when working with -" gofmt, but it does keep struct literals properly indented.) -" :0 -- Align case labels with switch statement -" l1 -- Always align case body relative to case labels -" J1 -- Indent JSON-style objects (properly indents struct-literals) -" (0, Ws -- Indent lines inside of unclosed parentheses by one shiftwidth -" m1 -- Align closing parenthesis line with first non-blank of matching -" parenthesis line -" -" Known issue: Trying to do a multi-line struct literal in a short variable -" declaration will not indent properly. -setlocal cinoptions+=+0,L0,:0,l1,J1,(0,Ws,m1