2019-03-11 16:39:30 -04:00
|
|
|
" don't spam the user when Vim is started in Vi compatibility mode
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
function! go#auto#template_autocreate()
|
|
|
|
if !go#config#TemplateAutocreate() || !&modifiable
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" create new template from scratch
|
|
|
|
call go#template#create()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#echo_go_info()
|
|
|
|
if !go#config#EchoGoInfo()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('v:completed_item') || empty(v:completed_item)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let item = v:completed_item
|
|
|
|
|
|
|
|
if !has_key(item, "info")
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if empty(item.info)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#auto_type_info()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !go#config#AutoTypeInfo() || !isdirectory(expand('%:p:h'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" GoInfo automatic update
|
|
|
|
call go#tool#Info(0)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#auto_sameids()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !go#config#AutoSameids() || !isdirectory(expand('%:p:h'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" GoSameId automatic update
|
|
|
|
call go#guru#SameIds(0)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#fmt_autosave()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !(go#config#FmtAutosave() && isdirectory(expand('%:p:h')) && expand('<afile>:p') == expand('%:p'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Go code formatting on save
|
|
|
|
call go#fmt#Format(-1)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#metalinter_autosave()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !go#config#MetalinterAutosave() || !isdirectory(expand('%:p:h'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" run gometalinter on save
|
2019-03-27 11:08:56 -04:00
|
|
|
call go#lint#Gometa(!g:go_jump_to_error, 1)
|
2019-03-11 16:39:30 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#modfmt_autosave()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !(go#config#ModFmtAutosave() && isdirectory(expand('%:p:h')) && expand('<afile>:p') == expand('%:p'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" go.mod code formatting on save
|
|
|
|
call go#mod#Format()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#auto#asmfmt_autosave()
|
2019-08-22 11:36:17 -04:00
|
|
|
if !(go#config#AsmfmtAutosave() && isdirectory(expand('%:p:h')) && expand('<afile>:p') == expand('%:p'))
|
2019-03-11 16:39:30 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Go asm formatting on save
|
|
|
|
call go#asmfmt#Format()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" restore Vi compatibility settings
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
|
|
|
" vim: sw=2 ts=2 et
|