aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/coc/source/khard.vim39
-rw-r--r--ftplugin/mail.vim11
2 files changed, 36 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
diff --git a/ftplugin/mail.vim b/ftplugin/mail.vim
new file mode 100644
index 0000000..af35487
--- /dev/null
+++ b/ftplugin/mail.vim
@@ -0,0 +1,11 @@
+function s:update_wrapping()
+ if coc#source#khard#should_complete({ 'line': getline('.') })
+ " temporarily disable line wrapping
+ setlocal formatoptions-=tc
+ else
+ " re-enable line wrapping
+ setlocal formatoptions+=tc
+ endif
+endfunction
+
+autocmd CursorMoved,CursorMovedI <buffer> call s:update_wrapping()