summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-17 19:39:45 +0100
committerw0rp <devw0rp@gmail.com>2018-07-17 19:39:45 +0100
commit7952ebe77ef3f6d5c98ec155ea8aad46652e7077 (patch)
tree3bd5bdbf8287057c189dd5dffc682e9842b25700 /autoload
parenta01fab2ee6dd827d555792f69fc30443a64dac5f (diff)
downloadale-7952ebe77ef3f6d5c98ec155ea8aad46652e7077.zip
#1700 - Don't send <C-x><C-o> for completion in Insert mode
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/completion.vim66
1 files changed, 41 insertions, 25 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index 0f9ae4e0..e7da4028 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -1,6 +1,17 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Completion support for LSP linters
+" The omnicompletion menu is shown through a special Plug mapping which is
+" only valid in Insert mode. This way, feedkeys() won't send these keys if you
+" quit Insert mode quickly enough.
+inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
+" If we hit the key sequence in normal mode, then we won't show the menu, so
+" we should restore the old settings right away.
+nnoremap <silent> <Plug>(ale_show_completion_menu) :call ale#completion#RestoreCompletionOptions()<CR>
+cnoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
+vnoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
+onoremap <silent> <Plug>(ale_show_completion_menu) <Nop>
+
let g:ale_completion_delay = get(g:, 'ale_completion_delay', 100)
let g:ale_completion_excluded_words = get(g:, 'ale_completion_excluded_words', [])
let g:ale_completion_max_suggestions = get(g:, 'ale_completion_max_suggestions', 50)
@@ -129,7 +140,16 @@ function! ale#completion#Filter(buffer, suggestions, prefix) abort
return l:filtered_suggestions
endfunction
-function! s:ReplaceCompleteopt() abort
+function! s:ReplaceCompletionOptions() abort
+ " Remember the old omnifunc value, if there is one.
+ " If we don't store an old one, we'll just never reset the option.
+ " This will stop some random exceptions from appearing.
+ if !exists('b:ale_old_omnifunc') && !empty(&l:omnifunc)
+ let b:ale_old_omnifunc = &l:omnifunc
+ endif
+
+ let &l:omnifunc = 'ale#completion#OmniFunc'
+
if !exists('b:ale_old_completopt')
let b:ale_old_completopt = &l:completeopt
endif
@@ -141,6 +161,22 @@ function! s:ReplaceCompleteopt() abort
endif
endfunction
+function! ale#completion#RestoreCompletionOptions() abort
+ " Reset settings when completion is done.
+ if exists('b:ale_old_omnifunc')
+ if b:ale_old_omnifunc isnot# 'pythoncomplete#Complete'
+ let &l:omnifunc = b:ale_old_omnifunc
+ endif
+
+ unlet b:ale_old_omnifunc
+ endif
+
+ if exists('b:ale_old_completopt')
+ let &l:completeopt = b:ale_old_completopt
+ unlet b:ale_old_completopt
+ endif
+endfunction
+
function! ale#completion#OmniFunc(findstart, base) abort
if a:findstart
let l:line = b:ale_completion_info.line
@@ -163,7 +199,7 @@ function! ale#completion#OmniFunc(findstart, base) abort
let b:ale_completion_result = function(l:parser)(l:response)
endif
- call s:ReplaceCompleteopt()
+ call s:ReplaceCompletionOptions()
return get(b:, 'ale_completion_result', [])
endif
@@ -174,20 +210,12 @@ function! ale#completion#Show(response, completion_parser) abort
return
endif
- " Remember the old omnifunc value, if there is one.
- " If we don't store an old one, we'll just never reset the option.
- " This will stop some random exceptions from appearing.
- if !exists('b:ale_old_omnifunc') && !empty(&l:omnifunc)
- let b:ale_old_omnifunc = &l:omnifunc
- endif
-
" Set the list in the buffer, temporarily replace omnifunc with our
" function, and then start omni-completion.
let b:ale_completion_response = a:response
let b:ale_completion_parser = a:completion_parser
- let &l:omnifunc = 'ale#completion#OmniFunc'
- call s:ReplaceCompleteopt()
- call ale#util#FeedKeys("\<C-x>\<C-o>", 'n')
+ call s:ReplaceCompletionOptions()
+ call ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")
endfunction
function! s:CompletionStillValid(request_id) abort
@@ -523,19 +551,7 @@ endfunction
function! ale#completion#Done() abort
silent! pclose
- " Reset settings when completion is done.
- if exists('b:ale_old_omnifunc')
- if b:ale_old_omnifunc isnot# 'pythoncomplete#Complete'
- let &l:omnifunc = b:ale_old_omnifunc
- endif
-
- unlet b:ale_old_omnifunc
- endif
-
- if exists('b:ale_old_completopt')
- let &l:completeopt = b:ale_old_completopt
- unlet b:ale_old_completopt
- endif
+ call ale#completion#RestoreCompletionOptions()
let s:last_done_pos = getcurpos()[1:2]
endfunction