1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated vimrc

This commit is contained in:
amix
2015-07-13 11:22:46 +01:00
parent 9a2843c2a5
commit d7752b59ae
301 changed files with 4699 additions and 7969 deletions

View File

@ -1,5 +1,5 @@
function! go#tool#Files()
if IsWin()
if go#util#IsWin()
let command = 'go list -f "{{range $f := .GoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}"'
else
let command = "go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}'"
@ -9,7 +9,7 @@ function! go#tool#Files()
endfunction
function! go#tool#Deps()
if IsWin()
if go#util#IsWin()
let command = 'go list -f "{{range $f := .Deps}}{{$f}}{{printf \"\n\"}}{{end}}"'
else
let command = "go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}'"
@ -20,7 +20,7 @@ endfunction
function! go#tool#Imports()
let imports = {}
if IsWin()
if go#util#IsWin()
let command = 'go list -f "{{range $f := .Imports}}{{$f}}{{printf \"\n\"}}{{end}}"'
else
let command = "go list -f $'{{range $f := .Imports}}{{$f}}\n{{end}}'"
@ -41,7 +41,17 @@ function! go#tool#Imports()
endfunction
function! go#tool#ShowErrors(out)
" cd into the current files directory. This is important so fnamemodify
" does create a full path for outputs when the token is only a single file
" name (such as for a go test output, i.e.: 'demo_test.go'). For other
" outputs, such as 'go install' we already get an absolute path (i.e.:
" '../foo/foo.go') and fnamemodify successfuly creates the full path.
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let current_dir = getcwd()
execute cd . fnameescape(expand("%:p:h"))
let errors = []
for line in split(a:out, '\n')
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
@ -49,7 +59,7 @@ function! go#tool#ShowErrors(out)
if !empty(fatalerrors)
call add(errors, {"text": fatalerrors[1]})
elseif !empty(tokens)
call add(errors, {"filename" : expand("%:p:h:") . "/" . tokens[1],
call add(errors, {"filename" : fnamemodify(tokens[1], ':p'),
\"lnum": tokens[2],
\"text": tokens[3]})
elseif !empty(errors)
@ -61,6 +71,9 @@ function! go#tool#ShowErrors(out)
endif
endfor
" return back to old dir once we are finished with populating the errors
execute cd . fnameescape(current_dir)
if !empty(errors)
call setqflist(errors, 'r')
return
@ -73,14 +86,19 @@ function! go#tool#ShowErrors(out)
endfunction
function! go#tool#ExecuteInDir(cmd) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
execute cd.'`=expand("%:p:h")`'
execute cd . fnameescape(expand("%:p:h"))
let out = system(a:cmd)
finally
execute cd.'`=dir`'
execute cd . fnameescape(dir)
endtry
let $GOPATH = old_gopath
return out
endfunction
@ -97,56 +115,13 @@ function! go#tool#Exists(importpath)
return 0
endfunction
" BinPath checks whether the given binary exists or not and returns the path
" of the binary. It returns an empty string doesn't exists.
function! go#tool#BinPath(binpath)
" remove whitespaces if user applied something like 'goimports '
let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '')
" if it's in PATH just return it
if executable(binpath)
return binpath
endif
" just get the basename
let basename = fnamemodify(binpath, ":t")
" check if we have an appropriate bin_path
let go_bin_path = GetBinPath()
if empty(go_bin_path)
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
return ""
endif
" append our GOBIN and GOPATH paths and be sure they can be found there...
" let us search in our GOBIN and GOPATH paths
let old_path = $PATH
let $PATH = $PATH . PathSep() .go_bin_path
if !executable(basename)
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
" restore back!
let $PATH = old_path
return ""
endif
let $PATH = old_path
let sep = '/'
if IsWin()
let sep = '\'
endif
return go_bin_path . sep . basename
endfunction
" following two functions are from: https://github.com/mattn/gist-vim
" thanks @mattn
function! s:get_browser_command()
let go_play_browser_command = get(g:, 'go_play_browser_command', '')
if go_play_browser_command == ''
if IsWin()
if go#util#IsWin()
let go_play_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
let go_play_browser_command = 'open %URL%'
@ -183,5 +158,4 @@ function! go#tool#OpenBrowser(url)
endif
endfunction
" vim:ts=4:sw=4:et