diff options
author | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2017-06-25 13:02:45 +0900 |
---|---|---|
committer | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2017-06-25 13:02:45 +0900 |
commit | 03e449c981e3388516827506039915dd3afe3257 (patch) | |
tree | 5ae8a976b1d735fc3d704aff6f22281b468f78aa /autoload/deoplete/mapping.vim | |
parent | d19ed16ee619409390b21607070c379862734601 (diff) | |
download | deoplete.nvim-03e449c981e3388516827506039915dd3afe3257.zip |
Add deoplete#complete_common_string()
Diffstat (limited to 'autoload/deoplete/mapping.vim')
-rw-r--r-- | autoload/deoplete/mapping.vim | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/autoload/deoplete/mapping.vim b/autoload/deoplete/mapping.vim index 39dee36..fb3b1ff 100644 --- a/autoload/deoplete/mapping.vim +++ b/autoload/deoplete/mapping.vim @@ -49,3 +49,38 @@ function! deoplete#mapping#_rpcrequest_wrapper(sources) abort \ deoplete#init#_context('Manual', a:sources)) return '' endfunction +function! deoplete#mapping#_undo_completion() abort +endfunction +function! deoplete#mapping#_complete_common_string() abort + if deoplete#initialize() + return + endif + + " Get cursor word. + let complete_str = matchstr(deoplete#util#get_input(''), '\w*$') + + if complete_str == '' || !has_key(g:deoplete#_context, 'candidates') + return '' + endif + + let candidates = filter(copy(g:deoplete#_context.candidates), + \ 'stridx(tolower(v:val.word), tolower(complete_str)) == 0') + + if empty(candidates) + return '' + endif + + let common_str = candidates[0].word + for candidate in candidates[1:] + while stridx(tolower(candidate.word), tolower(common_str)) != 0 + let common_str = common_str[: -2] + endwhile + endfor + + if common_str == '' || complete_str ==? common_str + return '' + endif + + return (pumvisible() ? "\<C-e>" : '') + \ . repeat("\<BS>", strchars(complete_str)) . common_str +endfunction |