1
0
Fork 0
mirror of synced 2024-11-30 04:35:35 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/alternate.vim

31 lines
914 B
VimL
Raw Normal View History

2016-02-17 14:03:42 -05:00
" By default use edit (current buffer view) to switch
if !exists("g:go_alternate_mode")
let g:go_alternate_mode = "edit"
endif
" Test alternates between the implementation of code and the test code.
function! go#alternate#Switch(bang, cmd)
2016-03-14 06:04:57 -04:00
let file = expand('%')
if empty(file)
call go#util#EchoError("no buffer name")
2016-02-17 14:03:42 -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-17 14:03:42 -05:00
else
2016-03-14 06:04:57 -04:00
call go#util#EchoError("not a go file")
return
2016-02-17 14:03:42 -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)
execute ":" . g:go_alternate_mode . " " . alt_file
2016-02-17 14:03:42 -05:00
else
2016-03-14 06:04:57 -04:00
execute ":" . a:cmd . " " . alt_file
2016-02-17 14:03:42 -05:00
endif
endfunction