Skip to content

Commit

Permalink
Add config options for asyncomplete integration
Browse files Browse the repository at this point in the history
'splitmode', 'filter_prefix', 'show_incomplete', 'sort_candidates'

See code comment below for details.
  • Loading branch information
wellle committed Nov 25, 2017
1 parent 42c2adb commit e63902e
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions autoload/asyncomplete/sources/tmuxcomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ let s:defaultopts = {
\ 'completor': function('asyncomplete#sources#tmuxcomplete#completor'),
\ }

" 'splitmode' can be 'words', 'lines', 'ilines', or 'linies,words'
" 'ilines' is inner line, starting with a word character (ignoring special
" chararcters in front)
" 'ilines,words' completes both lines and words
" more combinations can be added per request
"
" if 'filter_prefix' is enabled, we will filter candidates based on the entered
" text, this usually gives faster results. for fuzzy matching this should be
" disabled
"
" if there you are using many tmux windows with a lot of text in it completion
" can be slow. that's why we start showing candidates as soon as they come in
" if you prefer to only see candidates once the list is complete, you can
" disable this 'show_incomplete'
"
" 'sort_candidates' controls whether we sort candidates from tmux externally.
" if it's enabled we can't get early incomplete results. if you have
" 'show_incomplete' disabled, this might get slightly quicker results and
" potentially better sorted completions.
let s:defaultconfig = {
\ 'splitmode': 'words',
\ 'filter_prefix': 1,
\ 'show_incomplete': 1,
\ 'sort_candidates': 0
\ }

function! asyncomplete#sources#tmuxcomplete#register(opts)
let l:opts = extend(copy(s:defaultopts), a:opts)
call asyncomplete#register_source(l:opts)
Expand All @@ -18,10 +44,14 @@ function! asyncomplete#sources#tmuxcomplete#completor(opt, ctx)
endif
" echom '#completor for ' . l:kw

let l:config = extend(copy(s:defaultconfig), get(a:opt, 'config', {}))
" echom 'config ' . string(l:config)

let l:params = {
\ 'name': a:opt['name'],
\ 'ctx': a:ctx,
\ 'startcol': a:ctx['col'] - l:kwlen,
\ 'config': l:config,
\ 'kw': l:kw,
\ 'raw': [],
\ 'mapped': []
Expand All @@ -31,7 +61,16 @@ function! asyncomplete#sources#tmuxcomplete#completor(opt, ctx)
" completions later, even if the context changed in between.
call s:complete(l:params, [''], 1)

let l:cmd = tmuxcomplete#getcommandlist(l:kw, 'words')
if !l:config['filter_prefix']
let l:kw = ''
endif

let l:cmd = tmuxcomplete#getcommandlist(l:kw, l:config['splitmode'])
if !l:config['sort_candidates']
call add(l:cmd, '-n')
endif
" echom 'cmd ' . string(l:cmd)

let l:jobid = async#job#start(l:cmd, {
\ 'on_stdout': function('s:stdout', [l:params]),
\ 'on_exit': function('s:exit', [l:params]),
Expand All @@ -43,9 +82,11 @@ function! s:stdout(params, id, data, event) abort

call extend(a:params['raw'], a:data) " to be mapped differently again on exit

" surround with pipes while incomplete
call extend(a:params['mapped'], map(copy(a:data), '{"word":v:val,"menu":"|' . a:params['name'] . '|"}'))
call s:complete(a:params, a:params['mapped'], 1)
if a:params['config']['show_incomplete']
" surround with pipes while incomplete
call extend(a:params['mapped'], map(copy(a:data), '{"word":v:val,"menu":"|' . a:params['name'] . '|"}'))
call s:complete(a:params, a:params['mapped'], 1)
endif
endfunction

function! s:exit(params, id, data, event) abort
Expand Down

0 comments on commit e63902e

Please sign in to comment.