Last active
August 29, 2015 14:04
-
-
Save sgur/4e1cc8e93798b8fe9621 to your computer and use it in GitHub Desktop.
Completion using codic-vim
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
inoremap <silent> <C-x><C-t> <C-R>=<SID>codic_complete()<CR> | |
function! s:codic_complete() | |
let line = getline('.') | |
let start = match(line, '\k\+$') | |
let cand = s:codic_candidates(line[start :]) | |
call complete(start +1, cand) | |
return '' | |
endfunction | |
function! s:codic_candidates(arglead) | |
let cand = codic#search(a:arglead, 30) | |
" error | |
if type(cand) == type(0) | |
return [] | |
endif | |
" english -> english terms | |
if a:arglead =~# '^\w\+$' | |
return map(cand, '{"word": v:val["label"], "menu": join(map(copy(v:val["values"]), "v:val.word"), ",")}') | |
endif | |
" japanese -> english terms | |
return s:reverse_candidates(cand) | |
endfunction | |
function! s:reverse_candidates(cand) | |
let _ = [] | |
for c in a:cand | |
for v in c.values | |
call add(_, {"word": v.word, "menu": !empty(v.desc) ? v.desc : c.label }) | |
endfor | |
endfor | |
return _ | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment