From 37713a29ef509bfd96c4af36c43796ee05653622 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Fri, 8 Feb 2019 00:23:18 +0100 Subject: [PATCH] Initial commit --- .gitignore | 8 ++++++++ LICENSE | 20 ++++++++++++++++++++ README.md | 4 ++++ autoload/ncm2_khard.vim | 33 +++++++++++++++++++++++++++++++++ ncm2-plugin/ncm2_khard.vim | 1 + pythonx/ncm2_khard.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 autoload/ncm2_khard.vim create mode 100644 ncm2-plugin/ncm2_khard.vim create mode 100644 pythonx/ncm2_khard.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84fe9ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.swp +*.pyc +__pycache__ +/node_modules +/doc/tags +/.envrc +/test.vim +/nvim.log* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a54395 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright © 2019 maximewack@free.fr + +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..0c69e6d --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# ncm2-khard + +This ncm2 plugin provide email address completion from khard. + diff --git a/autoload/ncm2_khard.vim b/autoload/ncm2_khard.vim new file mode 100644 index 0000000..aca0946 --- /dev/null +++ b/autoload/ncm2_khard.vim @@ -0,0 +1,33 @@ +if get(s:, 'loaded', 0) + finish +endif +let s:loaded = 1 + +let g:ncm2_khard#proc = yarp#py3({ + \ 'module': 'ncm2_khard', + \ 'on_load': { -> ncm2#set_ready(g:ncm2_khard#source)} + \ }) + +let g:ncm2_khard#source = extend(get(g:, 'ncm2_khard#source', {}), { + \ 'name': 'khard', + \ 'ready': 0, + \ 'priority': 5, + \ 'mark': 'b', + \ 'scope': ['mail'], + \ 'complete_pattern': ['^To: ', '^Cc: ', '^Bcc: '], + \ 'on_complete': 'ncm2_khard#on_complete', + \ 'on_warmup': 'ncm2_khard#on_warmup', + \ }, 'keep') + +func! ncm2_khard#init() + call ncm2#register_source(g:ncm2_khard#source) +endfunc + +func! ncm2_khard#on_warmup(ctx) + call g:ncm2_khard#proc.jobstart() +endfunc + +func! ncm2_khard#on_complete(ctx) + call g:ncm2_khard#proc.try_notify('on_complete', a:ctx) +endfunc + diff --git a/ncm2-plugin/ncm2_khard.vim b/ncm2-plugin/ncm2_khard.vim new file mode 100644 index 0000000..0882e7b --- /dev/null +++ b/ncm2-plugin/ncm2_khard.vim @@ -0,0 +1 @@ +call ncm2_khard#init() diff --git a/pythonx/ncm2_khard.py b/pythonx/ncm2_khard.py new file mode 100644 index 0000000..d8b9a88 --- /dev/null +++ b/pythonx/ncm2_khard.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import vim +import subprocess +from ncm2 import Ncm2Source, getLogger +import re +from copy import deepcopy + +logger = getLogger(__name__) + + +class Source(Ncm2Source): + + def on_warmup(self, ctx): + shell_command = 'khard email --parsable | cut -f 1,2' + self.dictionary = subprocess.run(shell_command, shell = True, capture_output = True).stdout.decode('utf8').split('\n') + + def on_complete(self, ctx): + base = ctx['base'] + # matcher = self.matcher_get(ctx) + # matches = [] + + + self.complete(ctx, ctx['startccol'], self.dictionary) + + +source = Source(vim) + +on_complete = source.on_complete