All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 function! asyncomplete#utils#_on_change#textchangedp#init() abort
4 if exists('##TextChangedP')
5 call s:setup_if_required()
7 \ 'name': 'TextChangedP',
8 \ 'register': function('s:register'),
9 \ 'unregister': function('s:unregister'),
12 return { 'name': 'TextChangedP', 'error': 'Requires vim with TextChangedP support' }
16 function! s:setup_if_required() abort
17 augroup asyncomplete_utils_on_change_text_changed_p
19 autocmd InsertEnter * call s:on_insert_enter()
20 autocmd InsertLeave * call s:on_insert_leave()
21 autocmd TextChangedI * call s:on_text_changed_i()
22 autocmd TextChangedP * call s:on_text_changed_p()
26 function! s:register(cb) abort
27 call add(s:callbacks , a:cb)
30 function! s:unregister(obj, cb) abort
31 " TODO: remove from s:callbacks
34 function! s:on_insert_enter() abort
35 let l:context = asyncomplete#context()
36 let s:previous_context = {
37 \ 'lnum': l:context['lnum'],
38 \ 'col': l:context['col'],
39 \ 'typed': l:context['typed'],
43 function! s:on_insert_leave() abort
44 unlet! s:previous_context
47 function! s:on_text_changed_i() abort
48 call s:maybe_notify_on_change()
51 function! s:on_text_changed_p() abort
52 call s:maybe_notify_on_change()
55 function! s:maybe_notify_on_change() abort
56 if !exists('s:previous_context')
59 " We notify on_change callbacks only when the cursor position
61 " Unfortunatelly we need this check because in insert mode it
62 " is possible to have TextChangedI triggered when the completion
63 " context is not changed at all: When we close the completion
64 " popup menu via <C-e> or <C-y>. If we still let on_change
65 " do the completion in this case we never close the menu.
66 " Vim doesn't allow programmatically changing buffer content
67 " in insert mode, so by comparing the cursor's position and the
68 " completion base we know whether the context has changed.
69 let l:context = asyncomplete#context()
70 let l:previous_context = s:previous_context
71 let s:previous_context = {
72 \ 'lnum': l:context['lnum'],
73 \ 'col': l:context['col'],
74 \ 'typed': l:context['typed'],
76 if l:previous_context !=# s:previous_context
77 for l:Cb in s:callbacks