From 7dcb2f8946ef727330341930f304598140077a94 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 14 Mar 2024 09:07:24 +0100 Subject: add coc autocomplete source for completing contact email addresses from khard --- .config/nvim/autoload/coc/source/khard.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .config/nvim/autoload/coc/source/khard.vim (limited to '.config/nvim/autoload/coc/source') diff --git a/.config/nvim/autoload/coc/source/khard.vim b/.config/nvim/autoload/coc/source/khard.vim new file mode 100644 index 0000000..63dd8bd --- /dev/null +++ b/.config/nvim/autoload/coc/source/khard.vim @@ -0,0 +1,28 @@ +" 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 + + " plugin config + return { + \ 'priority': 9, + \ 'shortcut': 'khard', + \ 'filetypes': ['mail'], + \} +endfunction + +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) +endfunction + -- cgit v1.2.3