From f795769af03223e5e929c99c8b68d4ee075dad5a Mon Sep 17 00:00:00 2001 From: Nathan Grigg Date: Fri, 21 Nov 2014 17:01:12 -0800 Subject: Add omnicomplete function for account names --- autoload/beancount.vim | 28 ++++++++++++++++++++++++++++ ftplugin/beancount.vim | 3 +++ 2 files changed, 31 insertions(+) diff --git a/autoload/beancount.vim b/autoload/beancount.vim index 85adc3e..9430f02 100644 --- a/autoload/beancount.vim +++ b/autoload/beancount.vim @@ -36,3 +36,31 @@ function! beancount#align_commodity(line1, line2) endif endwhile endfunction + +" Complete account name. +function! beancount#complete_account(findstart, base) + if a:findstart + let l:col = searchpos('\s\zs', "bn", line("."))[1] + if col == 0 + return -1 + else + return col + endif + endif + + let l:pattern = '^\V\.\{10\}\s\+open\s\+\zs\S\*' . + \ substitute(a:base, ":", '\\S\\*:\\S\\*', "g") + let l:view = winsaveview() + let l:fe = &foldenable + set nofoldenable + call cursor(1, 1) + let l:matches = [] + while 1 + let l:cline = search(pattern, "W") + if l:cline == 0 | break | endif + call add(matches, expand("")) + endwhile + let &foldenable = l:fe + call winrestview(l:view) + return l:matches +endfunction diff --git a/ftplugin/beancount.vim b/ftplugin/beancount.vim index 4cf4bf8..277285e 100644 --- a/ftplugin/beancount.vim +++ b/ftplugin/beancount.vim @@ -37,3 +37,6 @@ function! s:InsertIncoming() endfunction command! -buffer Incoming call InsertIncoming() + + +setl omnifunc=beancount#complete_account -- cgit v1.2.3-2-gb3c3