-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvirtualsnip.vim
63 lines (55 loc) · 1.49 KB
/
virtualsnip.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
let g:virtualsnip#events = get(g:, 'virtualsnip#events', ['CompleteDone'])
let s:is_enabled = v:false
function! virtualsnip#enable() abort
augroup virtualsnip
autocmd!
autocmd InsertEnter * call s:on_event('InsertEnter')
autocmd CursorMovedI * call s:on_event('CursorMovedI')
autocmd InsertLeave * call s:clear()
augroup END
for event in g:virtualsnip#events
if exists('##' . event)
execute printf('autocmd virtualsnip %s * call s:on_event("%s")',
\ event, event)
endif
endfor
let s:is_enabled = v:true
endfunction
function! virtualsnip#disable() abort
augroup virtualsnip
autocmd!
augroup END
let s:is_enabled = v:false
endfunction
function! virtualsnip#is_enabled() abort
return s:is_enabled
endfunction
function! s:clear() abort
let s:last_world = {}
call virtualsnip#view#refresh({'texts': []})
endfunction
function! s:calc(world) abort
let sh = virtualsnip#path#core()
let json = system(sh, json_encode(a:world))
return json_decode(json)
endfunction
function! s:on_event(event) abort
let world = virtualsnip#view#get_current_buffer_info()
if type(world) != type({}) || !s:world_is_changed(world)
return
endif
let value = s:calc(world)
call virtualsnip#view#refresh(value)
endfunction
let s:last_world = {}
function! s:world_is_changed(world) abort
if type(a:world) != type({})
return v:false
end
if s:last_world == a:world
return v:false
else
let s:last_world = a:world
return v:true
endif
endfunction