mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -196,6 +196,22 @@ function! go#util#Exec(cmd, ...) abort
|
||||
return call('s:exec', [[l:bin] + a:cmd[1:]] + a:000)
|
||||
endfunction
|
||||
|
||||
function! go#util#ExecInDir(cmd, ...) abort
|
||||
if !isdirectory(expand("%:p:h"))
|
||||
return ['', 1]
|
||||
endif
|
||||
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
let [l:out, l:err] = call('go#util#Exec', [a:cmd] + a:000)
|
||||
finally
|
||||
execute cd . fnameescape(l:dir)
|
||||
endtry
|
||||
return [l:out, l:err]
|
||||
endfunction
|
||||
|
||||
function! s:exec(cmd, ...) abort
|
||||
let l:bin = a:cmd[0]
|
||||
let l:cmd = go#util#Shelljoin([l:bin] + a:cmd[1:])
|
||||
@ -441,6 +457,104 @@ function! go#util#HasDebug(flag)
|
||||
return index(go#config#Debug(), a:flag) >= 0
|
||||
endfunction
|
||||
|
||||
function! go#util#OpenBrowser(url) abort
|
||||
let l:cmd = go#config#PlayBrowserCommand()
|
||||
if len(l:cmd) == 0
|
||||
redraw
|
||||
echohl WarningMsg
|
||||
echo "It seems that you don't have general web browser. Open URL below."
|
||||
echohl None
|
||||
echo a:url
|
||||
return
|
||||
endif
|
||||
|
||||
" if setting starts with a !.
|
||||
if l:cmd =~ '^!'
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=escape(shellescape(a:url), "#")', 'g')
|
||||
silent! exec l:cmd
|
||||
elseif cmd =~ '^:[A-Z]'
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=escape(a:url,"#")', 'g')
|
||||
exec l:cmd
|
||||
else
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=shellescape(a:url)', 'g')
|
||||
call go#util#System(l:cmd)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#util#ParseErrors(lines) abort
|
||||
let errors = []
|
||||
|
||||
for line in a:lines
|
||||
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
|
||||
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
|
||||
|
||||
if !empty(fatalerrors)
|
||||
call add(errors, {"text": fatalerrors[1]})
|
||||
elseif !empty(tokens)
|
||||
" strip endlines of form ^M
|
||||
let out = substitute(tokens[3], '\r$', '', '')
|
||||
|
||||
call add(errors, {
|
||||
\ "filename" : fnamemodify(tokens[1], ':p'),
|
||||
\ "lnum" : tokens[2],
|
||||
\ "text" : out,
|
||||
\ })
|
||||
elseif !empty(errors)
|
||||
" Preserve indented lines.
|
||||
" This comes up especially with multi-line test output.
|
||||
if match(line, '^\s') >= 0
|
||||
call add(errors, {"text": substitute(line, '\r$', '', '')})
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
return errors
|
||||
endfunction
|
||||
|
||||
" FilterValids filters the given items with only items that have a valid
|
||||
" filename. Any non valid filename is filtered out.
|
||||
function! go#util#FilterValids(items) abort
|
||||
" Remove any nonvalid filename from the location list to avoid opening an
|
||||
" empty buffer. See https://github.com/fatih/vim-go/issues/287 for
|
||||
" details.
|
||||
let filtered = []
|
||||
let is_readable = {}
|
||||
|
||||
for item in a:items
|
||||
if has_key(item, 'bufnr')
|
||||
let filename = bufname(item.bufnr)
|
||||
elseif has_key(item, 'filename')
|
||||
let filename = item.filename
|
||||
else
|
||||
" nothing to do, add item back to the list
|
||||
call add(filtered, item)
|
||||
continue
|
||||
endif
|
||||
|
||||
if !has_key(is_readable, filename)
|
||||
let is_readable[filename] = filereadable(filename)
|
||||
endif
|
||||
if is_readable[filename]
|
||||
call add(filtered, item)
|
||||
endif
|
||||
endfor
|
||||
|
||||
for k in keys(filter(is_readable, '!v:val'))
|
||||
echo "vim-go: " | echohl Identifier | echon "[run] Dropped " | echohl Constant | echon '"' . k . '"'
|
||||
echohl Identifier | echon " from location list (nonvalid filename)" | echohl None
|
||||
endfor
|
||||
|
||||
return filtered
|
||||
endfunction
|
||||
|
||||
function! go#util#ShowInfo(info)
|
||||
if empty(a:info)
|
||||
return
|
||||
endif
|
||||
|
||||
echo "vim-go: " | echohl Function | echon a:info | echohl None
|
||||
endfunction
|
||||
|
||||
" restore Vi compatibility settings
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
Reference in New Issue
Block a user