From 22b93aa532e6557e47deac76f7a755eb0a444ae7 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 21 Jun 2016 20:35:27 +0900 Subject: Rename mappings to mapping --- autoload/deoplete.vim | 45 ++++++++++++++++++++++++++ autoload/deoplete/handler.vim | 4 +-- autoload/deoplete/init.vim | 2 +- autoload/deoplete/mapping.vim | 41 ++++++++++++++++++++++++ autoload/deoplete/mappings.vim | 71 +++++------------------------------------- 5 files changed, 96 insertions(+), 67 deletions(-) create mode 100644 autoload/deoplete/mapping.vim (limited to 'autoload') 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() ? "\" : '') + \ . "\=deoplete#mapping#_rpcnotify_wrapper(" + \ . string(get(a:000, 0, [])) . ")\" +endfunction"}}} +function! deoplete#close_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\" : '' +endfunction"}}} +function! deoplete#smart_close_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\" : '' +endfunction"}}} +function! deoplete#cancel_popup() abort "{{{ + let g:deoplete#_context.position = getpos('.') + return pumvisible() ? "\" : '' +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() ? "\" : '' +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("\", 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("\\", '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 +" License: MIT license +"============================================================================= + +function! deoplete#mapping#_init() abort "{{{ + inoremap (deoplete_start_complete) + \ =deoplete#mapping#_do_complete(g:deoplete#_context) + inoremap (deoplete_auto_refresh) + \ =deoplete#mapping#refresh() +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 (deoplete_start_complete) - \ =deoplete#mappings#_do_complete(g:deoplete#_context) - inoremap (deoplete_auto_refresh) - \ =deoplete#mappings#refresh() -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() ? "\" : '') - \ . "\=deoplete#mappings#_rpcnotify_wrapper(" - \ . string(get(a:000, 0, [])) . ")\" -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() ? "\" : '' + return deoplete#close_popup() endfunction"}}} function! deoplete#mappings#smart_close_popup() abort "{{{ - let g:deoplete#_context.position = getpos('.') - return pumvisible() ? "\" : '' + return deoplete#smart_close_popup() endfunction"}}} function! deoplete#mappings#cancel_popup() abort "{{{ - let g:deoplete#_context.position = getpos('.') - return pumvisible() ? "\" : '' + 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() ? "\" : '' + 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("\", strchars(v:completed_item.word)) + return deoplete#undo_completion() endfunction"}}} " vim: foldmethod=marker -- cgit v1.2.3