aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/beancount.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/beancount.vim')
-rw-r--r--autoload/beancount.vim28
1 files changed, 28 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