aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-03-14 09:47:45 +0100
committerlonkaars <loek@pipeframe.xyz>2024-03-14 09:47:45 +0100
commitfb99d5be8362a32c47296cd5403ba935df3c14a6 (patch)
tree317c8a6e52329fc816f175ffaca013e3272bc8fc
initial commit (move from dotfiles)
-rw-r--r--autoload/coc/source/khard.vim28
-rw-r--r--license21
-rw-r--r--readme.md11
3 files changed, 60 insertions, 0 deletions
diff --git a/autoload/coc/source/khard.vim b/autoload/coc/source/khard.vim
new file mode 100644
index 0000000..63dd8bd
--- /dev/null
+++ b/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
+
diff --git a/license b/license
new file mode 100644
index 0000000..6faf3cf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 lonkaars
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..2d60d18
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,11 @@
+This adds a completion source for [coc.nvim][coc] that autocompletes email
+addresses for `ft=mail` buffers using khard.
+
+## installation (vim-plug)
+
+```
+Plug 'lonkaars/coc-khard'
+```
+
+[coc]: https://github.com/neoclide/coc.nvim
+