diff options
author | Johann Klähn <kljohann@gmail.com> | 2010-09-15 21:18:23 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2010-09-15 21:18:23 +0200 |
commit | 4d56417f750fe9eb473ae59eefb1a79bdc7d42f1 (patch) | |
tree | 05237bb32ea0b5abfce2b74c7c278c6be2f107d7 /contrib/vim/ftplugin/ledger.vim | |
parent | 2a82edb9f0b418ca6c855b09cf9ec6fbe4f88d47 (diff) | |
download | fork-ledger-4d56417f750fe9eb473ae59eefb1a79bdc7d42f1.tar.gz fork-ledger-4d56417f750fe9eb473ae59eefb1a79bdc7d42f1.tar.bz2 fork-ledger-4d56417f750fe9eb473ae59eefb1a79bdc7d42f1.zip |
vim. parse comments at eol in parse_body()
Diffstat (limited to 'contrib/vim/ftplugin/ledger.vim')
-rw-r--r-- | contrib/vim/ftplugin/ledger.vim | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index 2a0ce9eb..13602e5d 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -316,6 +316,9 @@ function! s:transaction.from_lnum(lnum) dict "{{{2 endif call remove(parts, 0) endfor + + " FIXME: this will break comments at the end of this 'head' line + " they need 2 spaces in front of the semicolon let trans['description'] = join(parts) return trans endf "}}} @@ -344,11 +347,18 @@ function! s:transaction.parse_body(...) dict "{{{2 return [] endif - let lnum = head + 1 + let lnum = head let tags = {} let postings = [] while lnum <= tail - let line = getline(lnum) + let line = split(getline(lnum), '\s*\%(\t\| \);', 1) + + if line[0] =~ '^\s\+[^[:blank:];]' + " posting + " FIXME: replaces original spacing in amount with single spaces + let parts = split(line[0], '\%(\t\| \)\s*') + call add(postings, {'account': parts[0], 'amount': join(parts[1:], ' ')}) + end " where are tags to be stored? if empty(postings) @@ -362,22 +372,17 @@ function! s:transaction.parse_body(...) dict "{{{2 let tag_container = postings[-1]['tags'] endif - if line =~ '^\s\+[^[:blank:];]' - " posting - " FIXME: comments at the eol - " FIXME: replaces original spacing in amount with single spaces - let parts = split(line, '\(\t\|\s\{2,}\)') - call add(postings, {'account': parts[0], 'amount': join(parts[1:])}) - elseif line =~ '^\s\+;\s*:' + let comment = join(line[1:], ' ;') + if comment =~ '^\s*:' " tags without values - for t in s:findall(line, ':\zs[^:[:blank:]]\([^:]*[^:[:blank:]]\)\?\ze:') + for t in s:findall(comment, ':\zs[^:[:blank:]]\([^:]*[^:[:blank:]]\)\?\ze:') let tag_container[t] = '' endfor - elseif line =~ '^\s\+;\s*[^:[:blank:]][^:]\+:' + elseif comment =~ '^\s*[^:[:blank:]][^:]\+:' " tag with value - let key = matchstr(line, '^\s\+;\s*\zs[^:]\+\ze:') + let key = matchstr(comment, '^\s*\zs[^:]\+\ze:') if ! empty(key) - let val = matchstr(line, ':\s*\zs.*\ze\s*$') + let val = matchstr(comment, ':\s*\zs.*\ze\s*$') let tag_container[key] = val endif endif |