aboutsummaryrefslogtreecommitdiffstats
path: root/rplugin/python3/deoplete/sources
diff options
context:
space:
mode:
authorJakob Schnitzer2017-03-08 23:46:48 -0300
committerJakob Schnitzer2017-03-20 11:12:45 -0300
commite72ec57a6f79ca72dfebdcb4e49ea753a8806d7d (patch)
treee479eab6cd827c9077ced2908e5b9c5e7285b205 /rplugin/python3/deoplete/sources
parent1437e782228dd649ee922fb3fb54c2b9a2b5052a (diff)
downloadvim-beancount-e72ec57a6f79ca72dfebdcb4e49ea753a8806d7d.tar.gz
deoplete: commodity completion
Match commodities after numbers. Close #33.
Diffstat (limited to 'rplugin/python3/deoplete/sources')
-rw-r--r--rplugin/python3/deoplete/sources/beancount.py21
1 files 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),