Skip to content

Commit 8559967

Browse files
committed
update for neovim
1 parent 30dd01a commit 8559967

1 file changed

Lines changed: 58 additions & 25 deletions

File tree

autoload/ctrlp.vim

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,9 @@ fu! ctrlp#files()
391391
en
392392
el
393393
sil! cal ctrlp#progress('Indexing...')
394-
try | cal s:UserCmd(lscmd)
395-
cat | retu [] | endt
394+
" try |
395+
cal s:UserCmd(lscmd)
396+
" cat | retu [] | endt
396397
en
397398
" Remove base directory
398399
cal ctrlp#rmbasedir(g:ctrlp_allfiles)
@@ -435,39 +436,63 @@ fu! s:GlobPath(dirs, depth)
435436
en
436437
endf
437438

438-
fu! ctrlp#async_glob_update_progress(timer)
439+
fu! s:async_glob_update_progress(timer)
439440
let s:must_wait = 0
440441
if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
441442
cal s:ForceUpdate()
442443
en
443444
if exists('s:timer')
444-
sil! cal ctrlp#statusline(len(g:ctrlp_allfiles))
445+
sil! cal ctrlp#statusline()
446+
endif
447+
448+
if !exists('s:job')
449+
timer_stop('s:timer')
450+
unlet s:timer
445451
endif
446452
endf
447453

448-
fu! ctrlp#async_glob_addfile(ch, file)
449-
call add(g:ctrlp_allfiles, a:file)
454+
fu! s:async_glob_on_stdout(job, data, ...)
455+
if type(a:data) ==# type([])
456+
call extend(g:ctrlp_allfiles, filter(a:data, 'v:val !=# ""'))
457+
else
458+
call add(g:ctrlp_allfiles, a:data)
459+
endif
450460
endf
451461

452-
fu! ctrlp#async_glob_onexit(ch, status)
462+
fu! s:async_glob_on_exit(...)
453463
let s:must_wait = 0
454-
if exists('s:timer')
455-
call timer_stop(s:timer)
456-
en
464+
if exists('s:job')
465+
unlet s:job
466+
endif
467+
cal s:stop_timer_if_exists()
457468
if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
458469
sil! cal ctrlp#statusline()
459470
cal s:ForceUpdate()
460471
en
461472
endf
462473

463474
fu! s:async_glob_abort()
464-
if exists('s:job')
465-
call job_stop(s:job)
466-
en
475+
cal s:stop_job_if_exists()
476+
cal s:stop_timer_if_exists()
477+
cal s:ForceUpdate()
478+
endf
479+
480+
fu! s:stop_timer_if_exists()
467481
if exists('s:timer')
468482
call timer_stop(s:timer)
483+
unlet s:timer
484+
en
485+
endf
486+
487+
fu! s:stop_job_if_exists()
488+
if exists('s:job')
489+
if !has('nvim')
490+
cal job_stop(s:job)
491+
else
492+
cal jobstop(s:job)
493+
endif
494+
unlet s:job
469495
en
470-
cal s:ForceUpdate()
471496
endf
472497

473498
fu! s:safe_printf(format, ...)
@@ -493,15 +518,23 @@ fu! s:UserCmd(lscmd)
493518
if (has('win32') || has('win64')) && match(&shell, 'sh') != -1
494519
let path = tr(path, '\', '/')
495520
en
496-
if s:usrcmdasync && v:version >= 800 && exists('*job_start')
497-
if exists('s:job')
498-
call job_stop(s:job)
499-
en
521+
if s:usrcmdasync && (v:version >= 800 || has('nvim')) && (exists('*job_start') || exists('*jobstart'))
522+
cal s:stop_job_if_exists()
500523
let g:ctrlp_allfiles = []
501524
let s:must_wait = 1
502-
let s:job = job_start([&shell, &shellcmdflag, printf(lscmd, path)],
503-
\ {'callback': 'ctrlp#async_glob_addfile', 'exit_cb': 'ctrlp#async_glob_onexit'})
504-
let s:timer = timer_start(250, 'ctrlp#async_glob_update_progress', {'repeat': -1})
525+
let argv = [&shell, &shellcmdflag, printf(lscmd, path)]
526+
if !has('nvim')
527+
let s:job = job_start(argv, {
528+
\ 'out_cb': function('s:async_glob_on_stdout'),
529+
\ 'exit_cb': function('s:async_glob_on_exit')
530+
\ })
531+
else
532+
let s:job = jobstart(argv, {
533+
\ 'on_stdout': function('s:async_glob_on_stdout'),
534+
\ 'on_exit': function('s:async_glob_on_exit')
535+
\ })
536+
endif
537+
let s:timer = timer_start(250, function('s:async_glob_update_progress'), {'repeat': -1})
505538
while s:must_wait
506539
sleep 50m
507540
endwhile
@@ -1564,7 +1597,7 @@ fu! s:compval(...)
15641597
retu a:1 - a:2
15651598
endf
15661599
" Statusline {{{2
1567-
fu! ctrlp#statusline(...)
1600+
fu! ctrlp#statusline()
15681601
if !exists('s:statypes')
15691602
let s:statypes = copy(s:coretypes)
15701603
if !empty(g:ctrlp_ext_vars)
@@ -1601,9 +1634,9 @@ fu! ctrlp#statusline(...)
16011634
let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>'
16021635
let dir = ' %=%<%#CtrlPMode2# %{getcwd()} %*'
16031636
let &l:stl = focus.byfname.regex.slider.marked.dir
1604-
if a:0
1605-
let &l:stl = '%#CtrlPStats# '.a:1.' '.&l:stl
1606-
endif
1637+
if exists('s:timer')
1638+
let &l:stl = '%#CtrlPStats# '.len(g:ctrlp_allfiles).' '.&l:stl
1639+
en
16071640
en
16081641
endf
16091642

0 commit comments

Comments
 (0)