diff options
author | Nathan Grigg | 2014-11-21 17:01:12 -0800 |
---|---|---|
committer | Nathan Grigg | 2014-11-21 17:01:12 -0800 |
commit | f795769af03223e5e929c99c8b68d4ee075dad5a (patch) | |
tree | 90911a28f8876ae8dea296524d5ca3ccaf416de3 | |
parent | 811be4ffbfbb7f0a11b71455b3ad52bd6e32bd7d (diff) | |
download | vim-beancount-f795769af03223e5e929c99c8b68d4ee075dad5a.tar.gz |
Add omnicomplete function for account names
Diffstat (limited to '')
-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 |