Skip to content

Commit 30dd01a

Browse files
committed
fix g:ctrlp_user_command_async
1 parent 2e773fd commit 30dd01a

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

autoload/ctrlp.vim

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ fu! s:Open()
330330
endf
331331

332332
fu! s:Close()
333+
cal s:async_glob_abort()
333334
cal s:buffunc(0)
334335
if winnr('$') == 1
335336
bw!
@@ -434,9 +435,39 @@ fu! s:GlobPath(dirs, depth)
434435
en
435436
endf
436437

437-
fu! ctrlp#addfile(ch, file)
438+
fu! ctrlp#async_glob_update_progress(timer)
439+
let s:must_wait = 0
440+
if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
441+
cal s:ForceUpdate()
442+
en
443+
if exists('s:timer')
444+
sil! cal ctrlp#statusline(len(g:ctrlp_allfiles))
445+
endif
446+
endf
447+
448+
fu! ctrlp#async_glob_addfile(ch, file)
438449
call add(g:ctrlp_allfiles, a:file)
439-
cal s:BuildPrompt(1)
450+
endf
451+
452+
fu! ctrlp#async_glob_onexit(ch, status)
453+
let s:must_wait = 0
454+
if exists('s:timer')
455+
call timer_stop(s:timer)
456+
en
457+
if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
458+
sil! cal ctrlp#statusline()
459+
cal s:ForceUpdate()
460+
en
461+
endf
462+
463+
fu! s:async_glob_abort()
464+
if exists('s:job')
465+
call job_stop(s:job)
466+
en
467+
if exists('s:timer')
468+
call timer_stop(s:timer)
469+
en
470+
cal s:ForceUpdate()
440471
endf
441472

442473
fu! s:safe_printf(format, ...)
@@ -467,7 +498,13 @@ fu! s:UserCmd(lscmd)
467498
call job_stop(s:job)
468499
en
469500
let g:ctrlp_allfiles = []
470-
let s:job = job_start([&shell, &shellcmdflag, printf(lscmd, path)], {'callback': 'ctrlp#addfile'})
501+
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})
505+
while s:must_wait
506+
sleep 50m
507+
endwhile
471508
elsei has('patch-7.4-597') && !(has('win32') || has('win64'))
472509
let g:ctrlp_allfiles = systemlist(s:safe_printf(lscmd, path))
473510
el
@@ -1054,6 +1091,7 @@ fu! s:ToggleByFname()
10541091
endf
10551092

10561093
fu! s:ToggleType(dir)
1094+
cal s:async_glob_abort()
10571095
let max = len(g:ctrlp_ext_vars) + len(s:coretypes) - 1
10581096
let next = s:walker(max, s:itemtype, a:dir)
10591097
cal ctrlp#setlines(next)
@@ -1526,7 +1564,7 @@ fu! s:compval(...)
15261564
retu a:1 - a:2
15271565
endf
15281566
" Statusline {{{2
1529-
fu! ctrlp#statusline()
1567+
fu! ctrlp#statusline(...)
15301568
if !exists('s:statypes')
15311569
let s:statypes = copy(s:coretypes)
15321570
if !empty(g:ctrlp_ext_vars)
@@ -1563,6 +1601,9 @@ fu! ctrlp#statusline()
15631601
let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>'
15641602
let dir = ' %=%<%#CtrlPMode2# %{getcwd()} %*'
15651603
let &l:stl = focus.byfname.regex.slider.marked.dir
1604+
if a:0
1605+
let &l:stl = '%#CtrlPStats# '.a:1.' '.&l:stl
1606+
endif
15661607
en
15671608
endf
15681609

@@ -2571,6 +2612,7 @@ endf
25712612
fu! s:setlines_pre(...)
25722613
if a:0 | let s:itemtype = a:1 | en
25732614
cal s:modevar()
2615+
let s:setlines_post_ended = 0
25742616
let g:ctrlp_lines = []
25752617
endf
25762618

@@ -2581,6 +2623,7 @@ fu! s:setlines_post()
25812623
cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])')
25822624
en
25832625
let g:ctrlp_lines = eval(types[s:itemtype])
2626+
let s:setlines_post_ended = 1
25842627
endf
25852628

25862629
fu! ctrlp#setlines(...)

doc/ctrlp.cnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ Before 2016/11/28~
14391439
+ 新命令: |YankLine()| 来复制整个文件。
14401440
+ 新选项: |g:ctrlp_types| 来选择內建类型。
14411441
+ 新特性: 异步在新线程中调用 |g:ctrlp_user_command| 。 设置
1442-
|g:user_command_async| 为1来启用。
1442+
|g:ctrlp_user_command_async| 为1来启用。
14431443
+ 为 delphi, rust 和 golang提供buffertag支持。
14441444
+ 新选项: |g:ctrlp_brief_prompt|,
14451445
|g:match_current_file|,

doc/ctrlp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ Before 2016/11/28~
15051505
+ New command: |YankLine()| to yank current line.
15061506
+ New option: |g:ctrlp_types| to select builtin modes.
15071507
+ New feature: asynchronized spawn of |g:ctrlp_user_command|. This enable
1508-
with set |g:user_command_async| to 1.
1508+
with set |g:ctrlp_user_command_async| to 1.
15091509
+ Support buffertag for delphi, rust and golang.
15101510
+ New option: |g:ctrlp_brief_prompt|,
15111511
|g:match_current_file|,

0 commit comments

Comments
 (0)