diff options
-rw-r--r-- | autoload/beancount.vim | 28 | ||||
-rw-r--r-- | ftplugin/beancount.vim | 3 |
2 files changed, 31 insertions, 0 deletions
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("<cWORD>")) + 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 <SID>InsertIncoming() + + +setl omnifunc=beancount#complete_account |