diff options
author | Johann Klähn <kljohann@gmail.com> | 2010-09-08 14:44:34 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2010-09-08 14:44:34 +0200 |
commit | ae3a8b6e11c6cc195282c005276220e6dc0218be (patch) | |
tree | 24b785209efbb0a784972381cb1e377e82ac7ee8 /contrib/vim/ftplugin/ledger.vim | |
parent | 84fea7f136891416978e3608a0627be84176a928 (diff) | |
download | fork-ledger-ae3a8b6e11c6cc195282c005276220e6dc0218be.tar.gz fork-ledger-ae3a8b6e11c6cc195282c005276220e6dc0218be.tar.bz2 fork-ledger-ae3a8b6e11c6cc195282c005276220e6dc0218be.zip |
vim. add case of automatic transactions
Diffstat (limited to 'contrib/vim/ftplugin/ledger.vim')
-rw-r--r-- | contrib/vim/ftplugin/ledger.vim | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index 8a752c21..13fb24cc 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -326,14 +326,25 @@ function! s:transaction.new() dict endf function! s:transaction.from_lnum(lnum) dict "{{{2 - let head = s:get_transaction_extents(a:lnum)[0] + let [head, tail] = s:get_transaction_extents(a:lnum) if ! head return endif let trans = copy(s:transaction) let trans['head'] = head + let trans['tail'] = tail + let parts = split(getline(head), '\s\+') + if parts[0] ==# '~' + let trans['expr'] = join(parts[1:]) + return trans + elseif parts[0] !~ '^\d' + " this case is avoided in s:get_transaction_extents(), + " but we'll check anyway. + return + endif + let description = [] for part in parts if ! has_key(trans, 'date') && part =~ '^\d' @@ -351,6 +362,10 @@ function! s:transaction.from_lnum(lnum) dict "{{{2 endf "}}} function! s:transaction.format_head() dict "{{{2 + if has_key(self, 'expr') + return '~ '.self['expr'] + endif + let parts = [] if has_key(self, 'date') | call add(parts, self['date']) | endif if has_key(self, 'code') | call add(parts, '('.self['code'].')') | endif @@ -369,7 +384,7 @@ function! s:get_transaction_extents(lnum) "{{{2 set nofoldenable call cursor(a:lnum, 0) - let head = search('^\d\S\+', 'bcnW') + let head = search('^[~[:digit:]]\S\+', 'bcnW') let tail = search('^[^;[:blank:]]\S\+', 'nW') let tail = tail > head ? tail - 1 : line('$') |