diff options
-rw-r--r-- | autoload/deoplete.vim | 45 | ||||
-rw-r--r-- | autoload/deoplete/handler.vim | 4 | ||||
-rw-r--r-- | autoload/deoplete/init.vim | 2 | ||||
-rw-r--r-- | autoload/deoplete/mapping.vim | 41 | ||||
-rw-r--r-- | autoload/deoplete/mappings.vim | 71 | ||||
-rw-r--r-- | doc/deoplete.txt | 41 |
6 files changed, 116 insertions, 88 deletions
diff --git a/autoload/deoplete.vim b/autoload/deoplete.vim index c6d58d6..96975fd 100644 --- a/autoload/deoplete.vim +++ b/autoload/deoplete.vim @@ -31,4 +31,49 @@ function! deoplete#enable_logging(level, logfile) abort "{{{ \ 'deoplete_enable_logging', a:level, a:logfile) endfunction"}}} +function! deoplete#manual_complete(...) abort "{{{ + if deoplete#initialize() + return + endif + + " Start complete. + return (pumvisible() ? "\<C-e>" : '') + \ . "\<C-r>=deoplete#mapping#_rpcnotify_wrapper(" + \ . string(get(a:000, 0, [])) . ")\<CR>" +endfunction"}}} +function! deoplete#close_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\<C-y>" : '' +endfunction"}}} +function! deoplete#smart_close_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\<C-e>" : '' +endfunction"}}} +function! deoplete#cancel_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\<C-e>" : '' +endfunction"}}} +function! deoplete#refresh() abort "{{{ + let g:deoplete#_context.refresh = 1 + if g:deoplete#_context.event ==# 'Manual' + let g:deoplete#_context.event = 'Refresh' + endif + return pumvisible() ? "\<C-e>" : '' +endfunction"}}} + +function! deoplete#undo_completion() abort "{{{ + if !exists('v:completed_item') || empty(v:completed_item) + return '' + endif + + let input = deoplete#util#get_input('') + if strridx(input, v:completed_item.word) != + \ len(input) - len(v:completed_item.word) + return '' + endif + + return deoplete#mapping#smart_close_popup() . + \ repeat("\<C-h>", strchars(v:completed_item.word)) +endfunction"}}} + " vim: foldmethod=marker diff --git a/autoload/deoplete/handler.vim b/autoload/deoplete/handler.vim index 45d9a6b..fb27120 100644 --- a/autoload/deoplete/handler.vim +++ b/autoload/deoplete/handler.vim @@ -45,14 +45,14 @@ function! s:completion_begin(event) abort "{{{ \ 'g:deoplete#_omni_patterns')) if pattern != '' && &l:omnifunc != '' \ && context.input =~# '\%('.pattern.'\)$' - call deoplete#mappings#_set_completeopt() + call deoplete#mapping#_set_completeopt() call feedkeys("\<C-x>\<C-o>", 'n') return endif endfor endfor - call deoplete#mappings#_set_completeopt() + call deoplete#mapping#_set_completeopt() call rpcnotify(g:deoplete#_channel_id, \ 'deoplete_auto_completion_begin', context) endfunction"}}} diff --git a/autoload/deoplete/init.vim b/autoload/deoplete/init.vim index c80cd4e..658bf2d 100644 --- a/autoload/deoplete/init.vim +++ b/autoload/deoplete/init.vim @@ -72,7 +72,7 @@ function! deoplete#init#_initialize() abort "{{{ return 1 endif - call deoplete#mappings#_init() + call deoplete#mapping#_init() call deoplete#init#_variables() let s:is_enabled = g:deoplete#enable_at_startup diff --git a/autoload/deoplete/mapping.vim b/autoload/deoplete/mapping.vim new file mode 100644 index 0000000..ad191c1 --- /dev/null +++ b/autoload/deoplete/mapping.vim @@ -0,0 +1,41 @@ +"============================================================================= +" FILE: mapping.vim +" AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com> +" License: MIT license +"============================================================================= + +function! deoplete#mapping#_init() abort "{{{ + inoremap <silent> <Plug>(deoplete_start_complete) + \ <C-r>=deoplete#mapping#_do_complete(g:deoplete#_context)<CR> + inoremap <silent> <Plug>(deoplete_auto_refresh) + \ <C-r>=deoplete#mapping#refresh()<CR> +endfunction"}}} + +function! deoplete#mapping#_do_complete(context) abort "{{{ + if b:changedtick == get(a:context, 'changedtick', -1) + \ && mode() ==# 'i' + call complete(a:context.complete_position + 1, a:context.candidates) + endif + + return '' +endfunction"}}} +function! deoplete#mapping#_set_completeopt() abort "{{{ + if exists('g:deoplete#_saved_completeopt') + return + endif + let g:deoplete#_saved_completeopt = &completeopt + set completeopt-=longest + set completeopt+=menuone + set completeopt-=menu + if &completeopt !~# 'noinsert\|noselect' + set completeopt+=noselect + endif +endfunction"}}} +function! deoplete#mapping#_rpcnotify_wrapper(sources) abort "{{{ + call rpcrequest(g:deoplete#_channel_id, + \ 'deoplete_manual_completion_begin', + \ deoplete#init#_context('Manual', a:sources)) + return '' +endfunction"}}} + +" vim: foldmethod=marker diff --git a/autoload/deoplete/mappings.vim b/autoload/deoplete/mappings.vim index c4fc223..30432a0 100644 --- a/autoload/deoplete/mappings.vim +++ b/autoload/deoplete/mappings.vim @@ -4,84 +4,27 @@ " License: MIT license "============================================================================= -function! deoplete#mappings#_init() abort "{{{ - inoremap <silent> <Plug>(deoplete_start_complete) - \ <C-r>=deoplete#mappings#_do_complete(g:deoplete#_context)<CR> - inoremap <silent> <Plug>(deoplete_auto_refresh) - \ <C-r>=deoplete#mappings#refresh()<CR> -endfunction"}}} - -function! deoplete#mappings#_do_complete(context) abort "{{{ - if b:changedtick == get(a:context, 'changedtick', -1) - \ && mode() ==# 'i' - call complete(a:context.complete_position + 1, a:context.candidates) - endif - - return '' -endfunction"}}} -function! deoplete#mappings#_set_completeopt() abort "{{{ - if exists('g:deoplete#_saved_completeopt') - return - endif - let g:deoplete#_saved_completeopt = &completeopt - set completeopt-=longest - set completeopt+=menuone - set completeopt-=menu - if &completeopt !~# 'noinsert\|noselect' - set completeopt+=noselect - endif -endfunction"}}} +" For compatibility. function! deoplete#mappings#manual_complete(...) abort "{{{ - if deoplete#initialize() - return - endif - - " Start complete. - return (pumvisible() ? "\<C-e>" : '') - \ . "\<C-r>=deoplete#mappings#_rpcnotify_wrapper(" - \ . string(get(a:000, 0, [])) . ")\<CR>" -endfunction"}}} -function! deoplete#mappings#_rpcnotify_wrapper(sources) abort "{{{ - call rpcrequest(g:deoplete#_channel_id, - \ 'deoplete_manual_completion_begin', - \ deoplete#init#_context('Manual', a:sources)) - return '' + return call('deoplete#manual_complete', a:000) endfunction"}}} function! deoplete#mappings#close_popup() abort "{{{ - let g:deoplete#_context.position = getpos('.') - return pumvisible() ? "\<C-y>" : '' + return deoplete#close_popup() endfunction"}}} function! deoplete#mappings#smart_close_popup() abort "{{{ - let g:deoplete#_context.position = getpos('.') - return pumvisible() ? "\<C-e>" : '' + return deoplete#smart_close_popup() endfunction"}}} function! deoplete#mappings#cancel_popup() abort "{{{ - let g:deoplete#_context.position = getpos('.') - return pumvisible() ? "\<C-e>" : '' + return deoplete#cancel_popup() endfunction"}}} function! deoplete#mappings#refresh() abort "{{{ - let g:deoplete#_context.refresh = 1 - if g:deoplete#_context.event ==# 'Manual' - let g:deoplete#_context.event = 'Refresh' - endif - return pumvisible() ? "\<C-e>" : '' + return deoplete#refresh() endfunction"}}} function! deoplete#mappings#undo_completion() abort "{{{ - if !exists('v:completed_item') || empty(v:completed_item) - return '' - endif - - let input = deoplete#util#get_input('') - if strridx(input, v:completed_item.word) != - \ len(input) - len(v:completed_item.word) - return '' - endif - - return deoplete#mappings#smart_close_popup() . - \ repeat("\<C-h>", strchars(v:completed_item.word)) + return deoplete#undo_completion() endfunction"}}} " vim: foldmethod=marker diff --git a/doc/deoplete.txt b/doc/deoplete.txt index d3585ee..3afa5c0 100644 --- a/doc/deoplete.txt +++ b/doc/deoplete.txt @@ -131,7 +131,7 @@ g:deoplete#auto_complete_start_length g:deoplete#disable_auto_complete It controls whether you invalidate automatic completion. If it is 1, automatic completion becomes invalid, but can use the - manual completion by |deoplete#mappings#manual_complete()|. + manual completion by |deoplete#manual_complete()|. Default value: 0 @@ -420,8 +420,8 @@ deoplete#enable_logging({level}, {logfile}) ------------------------------------------------------------------------------ KEY MAPPINGS *deoplete-key-mappings* - *deoplete#mappings#manual_complete()* -deoplete#mappings#manual_complete([{sources}]) + *deoplete#manual_complete()* +deoplete#manual_complete([{sources}]) Use this function with |:inoremap| <expr> (|:map-expression|). It calls the completion of deoplete. You can use it with custom completion setups. @@ -434,38 +434,37 @@ deoplete#mappings#manual_complete([{sources}]) typically. > inoremap <silent><expr> <Tab> - \ pumvisible() ? "\<C-n>" : - \ deoplete#mappings#manual_complete() + \ pumvisible() ? "\<C-n>" : deoplete#manual_complete() < - *deoplete#mappings#smart_close_popup()* -deoplete#mappings#smart_close_popup() + *deoplete#smart_close_popup()* +deoplete#smart_close_popup() Insert candidate and re-generate popup menu for deoplete. > inoremap <expr><C-h> - \ deoplete#mappings#smart_close_popup()."\<C-h>" + \ deoplete#smart_close_popup()."\<C-h>" inoremap <expr><BS> - \ deoplete#mappings#smart_close_popup()."\<C-h>" + \ deoplete#smart_close_popup()."\<C-h>" < Note: This mapping is conflicted with |SuperTab| or |endwise| plugins. Note: This key mapping is for <C-h> or <BS> keymappings. - *deoplete#mappings#close_popup()* -deoplete#mappings#close_popup() + *deoplete#close_popup()* +deoplete#close_popup() Insert candidate and close popup menu for deoplete. - *deoplete#mappings#undo_completion()* -deoplete#mappings#undo_completion() + *deoplete#undo_completion()* +deoplete#undo_completion() Undo inputted candidate. > - inoremap <expr><C-g> deoplete#mappings#undo_completion() + inoremap <expr><C-g> deoplete#undo_completion() < - *deoplete#mappings#refresh()* -deoplete#mappings#refresh() + *deoplete#refresh()* +deoplete#refresh() Refresh the candidates. > - inoremap <expr><C-l> deoplete#mappings#refresh() + inoremap <expr><C-l> deoplete#refresh() < ============================================================================== EXAMPLES *deoplete-examples* @@ -476,13 +475,13 @@ EXAMPLES *deoplete-examples* let g:deoplete#enable_smart_case = 1 " <C-h>, <BS>: close popup and delete backword char. - inoremap <expr><C-h> deoplete#mappings#smart_close_popup()."\<C-h>" - inoremap <expr><BS> deoplete#mappings#smart_close_popup()."\<C-h>" + inoremap <expr><C-h> deoplete#smart_close_popup()."\<C-h>" + inoremap <expr><BS> deoplete#smart_close_popup()."\<C-h>" " <CR>: close popup and save indent. inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> function! s:my_cr_function() abort - return deoplete#mappings#close_popup() . "\<CR>" + return deoplete#close_popup() . "\<CR>" endfunction < ============================================================================== @@ -1027,7 +1026,7 @@ new line, you should map <CR>. > inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> function! s:my_cr_function() abort - return deoplete#mappings#close_popup() . "\<CR>" + return deoplete#close_popup() . "\<CR>" endfunction Q: I want to use "vim-lua-ftplugin". |