diff options
author | Johann Klähn <kljohann@gmail.com> | 2009-06-25 16:50:09 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2009-06-29 16:41:34 +0200 |
commit | 7aabf2928571dd500668414a93b27a1d8a2e4f5e (patch) | |
tree | 7fc012084a1aabd53d364e0a03b686ede3170282 | |
parent | 4156a0488c08478298109f52bfa9c94d124397ac (diff) | |
download | ledger-7aabf2928571dd500668414a93b27a1d8a2e4f5e.tar.gz ledger-7aabf2928571dd500668414a93b27a1d8a2e4f5e.tar.bz2 ledger-7aabf2928571dd500668414a93b27a1d8a2e4f5e.zip |
vim. add function to collect all tags in a file
-rw-r--r-- | contrib/vim/ftplugin/ledger.vim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index f56864f5..cb9a9fc4 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -170,6 +170,32 @@ function! LedgerGetAccountHierarchy() return hierarchy endf +function! LedgerGetTags() "{{{2 + let alltags = {} + let metalines = map(getline(1, '$'), 'matchstr(v:val, ''^\s\+;\s*\zs.*$'')') + let metalines = filter(metalines, 'v:val != ""') + for line in metalines + " (spaces at beginning are stripped by matchstr!) + if line[0] == ':' + " multiple tags + for val in split(line, ':') + if val !~ '^\s*$' + let name = s:strip_spaces(val) + let alltags[name] = get(alltags, name, []) + endif + endfor + elseif line =~ '^.*:.*$' + " line with tag=value + let name = s:strip_spaces(split(line, ':')[0]) + let val = s:strip_spaces(join(split(line, ':')[1:], ':')) + let values = get(alltags, name, []) + call add(values, val) + let alltags[name] = values + endif + endfor + return alltags +endf "}}} + " Helper functions {{{1 function! s:multibyte_strlen(text) "{{{2 return strlen(substitute(a:text, ".", "x", "g")) @@ -189,3 +215,6 @@ function! s:get_columns(win) "{{{2 return columns endfunction "}}} +function! s:strip_spaces(text) "{{{2 + return matchstr(a:text, '^\s*\zs\S\%(.*\S\)\?\ze\s*$') +endf "}}} |