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

@ -79,14 +79,18 @@ function! go#fmt#Format(withGoimport)
" if it's something else than gofmt, we need to check the existing of that
" binary. For example if it's goimports, let us check if it's installed,
" if not the user get's a warning via go#tool#BinPath()
" if not the user get's a warning via go#path#CheckBinPath()
if fmt_command != "gofmt"
" check if the user has installed goimports
let bin_path = go#tool#BinPath(fmt_command)
let bin_path = go#path#CheckBinPath(fmt_command)
if empty(bin_path)
return
endif
" change GOPATH too, so goimports can pick up the correct library
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let fmt_command = bin_path
endif
@ -95,8 +99,16 @@ function! go#fmt#Format(withGoimport)
" execute our command...
let out = system(command . " " . l:tmpname)
let splitted = split(out, '\n')
"if there is no error on the temp file, gofmt again our original file
if fmt_command != "gofmt"
let $GOPATH = old_gopath
endif
"if there is no error on the temp file replace the output with the current
"file (if this fails, we can always check the outputs first line with:
"splitted =~ 'package \w\+')
if v:shell_error == 0
" remove undo point caused via BufWritePre
try | silent undojoin | catch | endtry
@ -106,8 +118,16 @@ function! go#fmt#Format(withGoimport)
let default_srr = &srr
set srr=>%s
" execufe gofmt on the current buffer and replace it
silent execute "%!" . command
" delete any leftover before we replace the whole file. Suppose the
" file had 20 lines, but new output has 10 lines, only 1-10 are
" replaced with setline, remaining lines 11-20 won't get touched. So
" remove them.
if line('$') > len(splitted)
execute len(splitted) .',$delete'
endif
" setline iterates over the list and replaces each line
call setline(1, splitted)
" only clear quickfix if it was previously set, this prevents closing
" other quickfixes
@ -122,7 +142,7 @@ function! go#fmt#Format(withGoimport)
elseif g:go_fmt_fail_silently == 0
"otherwise get the errors and put them to quickfix window
let errors = []
for line in split(out, '\n')
for line in splitted
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
if !empty(tokens)
call add(errors, {"filename": @%,