diff options
author | Jakob Schnitzer | 2017-03-09 17:46:09 -0300 |
---|---|---|
committer | Jakob Schnitzer | 2017-03-20 11:12:45 -0300 |
commit | 6357da05215fa95da4049384886e61be817efa74 (patch) | |
tree | be2e9dd15f3a53f35d5fac8cf430f62b99f5b3b1 /rplugin/python3/deoplete/sources | |
parent | e72ec57a6f79ca72dfebdcb4e49ea753a8806d7d (diff) | |
download | vim-beancount-6357da05215fa95da4049384886e61be817efa74.tar.gz |
deoplete: event completion
Close #34.
Diffstat (limited to '')
-rw-r--r-- | rplugin/python3/deoplete/sources/beancount.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/rplugin/python3/deoplete/sources/beancount.py b/rplugin/python3/deoplete/sources/beancount.py index f149ff0..ae6f6e1 100644 --- a/rplugin/python3/deoplete/sources/beancount.py +++ b/rplugin/python3/deoplete/sources/beancount.py @@ -5,7 +5,7 @@ from deoplete.source.base import Base try: from beancount.loader import load_file - from beancount.core.data import Open, Transaction + from beancount.core import data HAS_BEANCOUNT = True except ImportError: HAS_BEANCOUNT = False @@ -24,6 +24,7 @@ class Source(Base): self.name = 'beancount' self.mark = '[bc]' self.filetypes = ['beancount'] + self.rank = 500 self.min_pattern_length = 0 self.attributes = collections.defaultdict(list) @@ -49,6 +50,12 @@ class Source(Base): 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']] + # events + if re.search(r'event "[^"]*$', context['input']): + return [{ + 'word': '"{}"'.format(x), + 'kind': 'event' + } for x in attrs['events']] # commodity after number if re.search(r'([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?\s\w+', context['input']): @@ -77,23 +84,27 @@ class Source(Base): entries, _, options = load_file(self.vim.eval("beancount#get_root()")) accounts = set() + events = set() links = set() payees = set() tags = set() for entry in entries: - if isinstance(entry, Open): + if isinstance(entry, data.Open): accounts.add(entry.account) - elif isinstance(entry, Transaction): + elif isinstance(entry, data.Transaction): if entry.payee: payees.add(entry.payee) if hasattr(entry, 'links') and entry.links: links.update(entry.links) if hasattr(entry, 'tags') and entry.tags: tags.update(entry.tags) + if isinstance(entry, data.Event): + events.add(entry.type) self.attributes = { 'accounts': sorted(accounts), + 'events': sorted(events), 'commodities': options['commodities'], 'links': sorted(links), 'payees': sorted(payees), |