From e72ec57a6f79ca72dfebdcb4e49ea753a8806d7d Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Wed, 8 Mar 2017 23:46:48 -0300 Subject: deoplete: commodity completion Match commodities after numbers. Close #33. --- rplugin/python3/deoplete/sources/beancount.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/rplugin/python3/deoplete/sources/beancount.py b/rplugin/python3/deoplete/sources/beancount.py index dcc6a27..f149ff0 100644 --- a/rplugin/python3/deoplete/sources/beancount.py +++ b/rplugin/python3/deoplete/sources/beancount.py @@ -46,9 +46,16 @@ class Source(Base): if re.match(r'^(\s)+\w+$', context['input']): return [{'word': x, 'kind': 'account'} for x in attrs['accounts']] # directive followed by account - if re.match(r'(balance|document|note|open|close|pad(\s\S*)?)\s\w+$', - context['input']): + if re.search(r'(balance|document|note|open|close|pad(\s\S*)?)\s\w+$', + context['input']): return [{'word': x, 'kind': 'account'} for x in attrs['accounts']] + # commodity after number + if re.search(r'([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?\s\w+', + context['input']): + return [{ + 'word': x, + 'kind': 'commodity' + } for x in attrs['commodities']] if not context['complete_str']: return [] first = context['complete_str'][0] @@ -64,14 +71,15 @@ class Source(Base): return [] def __make_cache(self, context): + if not HAS_BEANCOUNT: + return + + entries, _, options = load_file(self.vim.eval("beancount#get_root()")) + accounts = set() links = set() payees = set() tags = set() - if HAS_BEANCOUNT: - entries, _, _ = load_file(self.vim.eval("beancount#get_root()")) - else: - entries = [] for entry in entries: if isinstance(entry, Open): @@ -86,6 +94,7 @@ class Source(Base): self.attributes = { 'accounts': sorted(accounts), + 'commodities': options['commodities'], 'links': sorted(links), 'payees': sorted(payees), 'tags': sorted(tags), -- cgit v1.2.3-2-gb3c3