Add sy#util#chdir()
This commit is contained in:
parent
304a2b9c27
commit
295e449db6
@ -25,16 +25,8 @@ function! sy#start() abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:chdir()
|
|
||||||
return haslocaldir()
|
|
||||||
\ ? 'lcd'
|
|
||||||
\ : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd'
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" sy_info is used in autoload/sy/repo
|
" sy_info is used in autoload/sy/repo
|
||||||
let b:sy_info = {
|
let b:sy_info = {
|
||||||
\ 'chdir': s:chdir(),
|
|
||||||
\ 'cwd': fnameescape(getcwd()),
|
|
||||||
\ 'dir': fnamemodify(sy_path, ':p:h'),
|
\ 'dir': fnamemodify(sy_path, ':p:h'),
|
||||||
\ 'path': sy#util#escape(sy_path),
|
\ 'path': sy#util#escape(sy_path),
|
||||||
\ 'file': sy#util#escape(fnamemodify(sy_path, ':t')),
|
\ 'file': sy#util#escape(fnamemodify(sy_path, ':t')),
|
||||||
|
@ -48,37 +48,46 @@ endfunction
|
|||||||
function! sy#repo#get_diff_start(vcs, do_register) abort
|
function! sy#repo#get_diff_start(vcs, do_register) abort
|
||||||
call sy#verbose('s:get_diff_start()', a:vcs)
|
call sy#verbose('s:get_diff_start()', a:vcs)
|
||||||
|
|
||||||
|
" Neovim
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
if exists('b:job_id_'.a:vcs)
|
if exists('b:job_id_'.a:vcs)
|
||||||
silent! call jobstop(b:job_id_{a:vcs})
|
silent! call jobstop(b:job_id_{a:vcs})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [cmd, options] = s:initialize_job(a:vcs, a:do_register)
|
let [cmd, options] = s:initialize_job(a:vcs, a:do_register)
|
||||||
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
let [cwd, chdir] = sy#util#chdir()
|
||||||
|
|
||||||
try
|
try
|
||||||
|
execute chdir fnameescape(b:sy_info.dir)
|
||||||
let b:job_id_{a:vcs} = jobstart(cmd, extend(options, {
|
let b:job_id_{a:vcs} = jobstart(cmd, extend(options, {
|
||||||
\ 'on_stdout': function('s:callback_stdout_nvim'),
|
\ 'on_stdout': function('s:callback_stdout_nvim'),
|
||||||
\ 'on_exit': function('s:callback_exit'),
|
\ 'on_exit': function('s:callback_exit'),
|
||||||
\ }))
|
\ }))
|
||||||
call sy#verbose('job_start()', a:vcs)
|
|
||||||
finally
|
finally
|
||||||
execute b:sy_info.chdir b:sy_info.cwd
|
execute chdir fnameescape(cwd)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
" Newer Vim
|
||||||
elseif v:version > 704 || v:version == 704 && has('patch1967')
|
elseif v:version > 704 || v:version == 704 && has('patch1967')
|
||||||
if exists('b:job_id_'.a:vcs)
|
if exists('b:job_id_'.a:vcs)
|
||||||
silent! call job_stop(b:job_id_{a:vcs})
|
silent! call job_stop(b:job_id_{a:vcs})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [cmd, options] = s:initialize_job(a:vcs, a:do_register)
|
let [cmd, options] = s:initialize_job(a:vcs, a:do_register)
|
||||||
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
let [cwd, chdir] = sy#util#chdir()
|
||||||
|
|
||||||
try
|
try
|
||||||
|
execute chdir fnameescape(b:sy_info.dir)
|
||||||
let b:job_id_{a:vcs} = job_start(cmd, {
|
let b:job_id_{a:vcs} = job_start(cmd, {
|
||||||
\ 'in_io': 'null',
|
\ 'in_io': 'null',
|
||||||
\ 'out_cb': function('s:callback_stdout_vim', options),
|
\ 'out_cb': function('s:callback_stdout_vim', options),
|
||||||
\ 'exit_cb': function('s:callback_exit', options),
|
\ 'exit_cb': function('s:callback_exit', options),
|
||||||
\ })
|
\ })
|
||||||
call sy#verbose('job_start()', a:vcs)
|
|
||||||
finally
|
finally
|
||||||
execute b:sy_info.chdir b:sy_info.cwd
|
execute chdir fnameescape(cwd)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
" Older Vim
|
||||||
else
|
else
|
||||||
let diff = split(s:run(a:vcs), '\n')
|
let diff = split(s:run(a:vcs), '\n')
|
||||||
call sy#repo#get_diff_{a:vcs}(v:shell_error, diff, a:do_register)
|
call sy#repo#get_diff_{a:vcs}(v:shell_error, diff, a:do_register)
|
||||||
@ -238,15 +247,16 @@ endfunction
|
|||||||
|
|
||||||
" Function: s:run {{{1
|
" Function: s:run {{{1
|
||||||
function! s:run(vcs)
|
function! s:run(vcs)
|
||||||
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
let [cwd, chdir] = sy#util#chdir()
|
||||||
try
|
try
|
||||||
|
execute chdir fnameescape(b:sy_info.dir)
|
||||||
let ret = system(s:expand_cmd(a:vcs))
|
let ret = system(s:expand_cmd(a:vcs))
|
||||||
catch
|
catch
|
||||||
" This exception message can be seen via :SignifyDebugUnknown.
|
" This exception message can be seen via :SignifyDebugUnknown.
|
||||||
" E.g. unquoted VCS programs in vcd_cmds can lead to E484.
|
" E.g. unquoted VCS programs in vcd_cmds can lead to E484.
|
||||||
let ret = v:exception .' at '. v:throwpoint
|
let ret = v:exception .' at '. v:throwpoint
|
||||||
finally
|
finally
|
||||||
execute b:sy_info.chdir b:sy_info.cwd
|
execute chdir fnameescape(cwd)
|
||||||
return ret
|
return ret
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -79,3 +79,11 @@ function! sy#util#shell_redirect(path) abort
|
|||||||
return &shellredir .' '. a:path
|
return &shellredir .' '. a:path
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function: #chdir {{{1
|
||||||
|
function! sy#util#chdir() abort
|
||||||
|
let chdir = haslocaldir()
|
||||||
|
\ ? 'lcd'
|
||||||
|
\ : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd'
|
||||||
|
return [getcwd(), chdir]
|
||||||
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user