diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-21 19:04:21 +0200 |
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-21 19:04:21 +0200 |
| commit | 48435b8b6023e3e81345e3f784fa011ae17794f5 (patch) | |
| tree | d525b3d4ef28e7bd33ae7acdf8e2d8f9b7bef479 | |
| parent | 5fd58b34e6903ee522f248cbe6b77fbde7d357ad (diff) | |
| -rw-r--r-- | autoload/coc/source/khard.vim | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/autoload/coc/source/khard.vim b/autoload/coc/source/khard.vim index 63dd8bd..3cd68de 100644 --- a/autoload/coc/source/khard.vim +++ b/autoload/coc/source/khard.vim @@ -1,13 +1,4 @@ -" global contacts list -let s:contacts = [] - -function! coc#source#khard#init() abort - " read contacts once on init - for line in systemlist('khard email --remove-first-line --parsable') - let [address, name, type] = split(line, "\t") - call add(s:contacts, printf('%s <%s>', name, address)) - endfor - +function! coc#source#khard#init() " plugin config return { \ 'priority': 9, @@ -16,13 +7,33 @@ function! coc#source#khard#init() abort \} endfunction -function coc#source#khard#should_complete(option) +function! coc#source#khard#should_complete(option) " only complete addresses on to, cc, bcc and reply-to header lines return tolower(a:option['line']) =~ '^\(to\|cc\|bcc\|reply-to\):' endfunction -function! coc#source#khard#complete(option, cb) abort - " init already loaded all the contacts, just forward them to CoC - call a:cb(s:contacts) +" global contacts list +let s:contacts = v:null +function! s:get_contacts() + if s:contacts isnot v:null + return s:contacts + endif + + let s:contacts = [] + let lines = systemlist('khard email --remove-first-line --parsable') + if v:shell_error != 0 + echoerr 'khard command failed with exit code ' . v:shell_error + return s:contacts + endif + for line in lines + let [address, name, type] = split(line, "\t") + call add(s:contacts, printf('%s <%s>', name, address)) + endfor + + return s:contacts +endfunction + +function! coc#source#khard#complete(option, cb) + call a:cb(s:get_contacts()) endfunction |