1
0
Fork 0
mirror of synced 2024-12-22 23:18:56 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/alternate.vim

36 lines
995 B
VimL
Raw Normal View History

2018-12-17 06:28:27 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2016-02-20 08:13:10 -05:00
" Test alternates between the implementation of code and the test code.
2016-12-27 09:46:49 -05:00
function! go#alternate#Switch(bang, cmd) abort
2016-03-14 06:04:57 -04:00
let file = expand('%')
if empty(file)
call go#util#EchoError("no buffer name")
2016-02-20 08:13:10 -05:00
return
2016-03-14 06:04:57 -04:00
elseif file =~# '^\f\+_test\.go$'
let l:root = split(file, '_test.go$')[0]
let l:alt_file = l:root . ".go"
elseif file =~# '^\f\+\.go$'
let l:root = split(file, ".go$")[0]
let l:alt_file = l:root . '_test.go'
2016-02-20 08:13:10 -05:00
else
2016-03-14 06:04:57 -04:00
call go#util#EchoError("not a go file")
return
2016-02-20 08:13:10 -05:00
endif
2016-03-14 06:04:57 -04:00
if !filereadable(alt_file) && !bufexists(alt_file) && !a:bang
call go#util#EchoError("couldn't find ".alt_file)
return
elseif empty(a:cmd)
2018-06-14 06:31:12 -04:00
execute ":" . go#config#AlternateMode() . " " . alt_file
2016-02-20 08:13:10 -05:00
else
2016-03-14 06:04:57 -04:00
execute ":" . a:cmd . " " . alt_file
2016-02-20 08:13:10 -05:00
endif
endfunction
2016-06-26 07:12:36 -04:00
2018-12-17 06:28:27 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et