Created
November 23, 2016 06:40
-
-
Save prabirshrestha/0b3b7b4e2112c662979bfeeec4e1edb7 to your computer and use it in GitHub Desktop.
async omnifunc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" save all the completions | |
let s:completions = [] | |
function! asyncomni#omnifunc(findstart, base) | |
if a:findstart | |
let l:line_string = getline('.') | |
let l:line = line('.') | |
let l:col = col('.') | |
" locate start of the word | |
let l:start = l:col -1 | |
while l:start > 0 && l:line_string[l:start -1] =~ '\a' | |
let l:start -= 1 | |
endwhile | |
echom 'l:start'.l:start | |
return l:start | |
endif | |
return s:completions | |
endfunction | |
let s:timer = -1 | |
function! s:complete() | |
if s:timer == -1 | |
let s:timer = timer_start(1000, function('s:loaded_completions')) | |
endif | |
endfunction | |
function! s:loaded_completions(timer) | |
let s:completions = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
" since this is a callback we got s:complete asynchrounsly | |
" refresh the list since this is async | |
if !empty(s:completions) | |
setlocal completeopt-=longest | |
setlocal completeopt+=menuone | |
setlocal completeopt-=menu | |
if &completeopt !~# 'noinsert\|noselect' | |
setlocal completeopt+=noselect | |
endif | |
call feedkeys("\<C-x>\<C-o>", 'n') | |
endif | |
endfunction | |
augroup asyncomni_completor | |
autocmd! | |
autocmd TextChangedI * call s:complete() | |
augroup end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if !exists('g:loaded_asyncomni') | |
let g:loaded_asyncomni = 1 | |
endif | |
let g:loaded_asyncomni = 1 | |
if exists('&omnifunc') | |
setl omnifunc+=asyncomni#omnifunc | |
endif |
This is a really interesting approach! Thanks for sharing! Glad I found it years later 😛 going to see if I can get it working in https://github.com/Olical/conjure
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit goes to https://github.com/maralla/completor.vim (https://github.com/maralla/completor.vim/blob/master/LICENSE)