diff --git a/autoload/gopher/go.vim b/autoload/gopher/go.vim index 95f7e1f..f8222de 100644 --- a/autoload/gopher/go.vim +++ b/autoload/gopher/go.vim @@ -27,7 +27,7 @@ fun! gopher#go#module() abort let l:wd = getcwd() try - call chdir(expand('%:h')) + call gopher#system#cd(expand('%:h')) let [l:out, l:err] = gopher#system#run(['go', 'list', '-m', '-f', \ "{{.Path}}\x01{{.Dir}}"]) if l:err @@ -35,7 +35,7 @@ fun! gopher#go#module() abort endif return split(l:out, "\x01") finally - call chdir(l:wd) + call gopher#system#cd(l:wd) endtry endfun diff --git a/autoload/gopher/system.vim b/autoload/gopher/system.vim index 1308fe0..94552f7 100644 --- a/autoload/gopher/system.vim +++ b/autoload/gopher/system.vim @@ -499,5 +499,14 @@ fun! gopher#system#closest(name) abort endwhile endfun +" Change the current directory to path. +fun! gopher#system#cd(path) abort + if exists('*chdir') + call chdir(a:path) + else + silent execute 'lcd' fnameescape(a:path) + endif +endfun + call s:init() " At end so entire file is parsed.