diff options
author | Johann Klähn <kljohann@gmail.com> | 2010-09-08 10:01:44 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2010-09-08 10:01:44 +0200 |
commit | 66b39c46d1cff25c5191c3a55dd14e9414413dca (patch) | |
tree | 1efe7aced608f71d513a2c63ac20f5b5bdc37edc /contrib/vim/ftplugin/ledger.vim | |
parent | cf40d1c9d79c0237d65ef55b8b2d79780f9b8669 (diff) | |
download | fork-ledger-66b39c46d1cff25c5191c3a55dd14e9414413dca.tar.gz fork-ledger-66b39c46d1cff25c5191c3a55dd14e9414413dca.tar.bz2 fork-ledger-66b39c46d1cff25c5191c3a55dd14e9414413dca.zip |
vim. add function to modify actual/effective date
This allows you to set the effective date in a convenient way.
Maybe I will add date selection using calendar.vim by Yasuhiro
Matsumoto. Until then, you can map this to use today's date:
call LedgerSetDate(line('.'), 'effective')
Diffstat (limited to 'contrib/vim/ftplugin/ledger.vim')
-rw-r--r-- | contrib/vim/ftplugin/ledger.vim | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index 6bbdbb50..1d624b14 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -273,6 +273,41 @@ function! LedgerSetTransactionState(lnum, char) "{{{1 " removing the state alltogether if a:char is empty endf "}}} +function! LedgerSetDate(lnum, type, ...) "{{{1 + let time = a:0 == 1 ? a:1 : localtime() + let trans = s:transaction.from_lnum(a:lnum) + if empty(trans) + return + endif + + let formatted = strftime('%Y/%m/%d', time) + if has_key(trans, 'date') && ! empty(trans['date']) + let date = split(trans['date'], '=') + else + let date = [formatted] + endif + + if a:type ==? 'actual' + let date[0] = formatted + elseif a:type ==? 'effective' + if time == 0 + " remove effective date + let date = [date[0]] + else + " set effective date + if len(date) >= 2 + let date[1] = formatted + else + call add(date, formatted) + endif + endif + endif + + let trans['date'] = join(date, '=') + + call setline(s:get_transaction_extents(a:lnum)[0], trans.format_head()) +endf "}}} + let s:transaction = {} "{{{1 function! s:transaction.new() dict return copy(s:transaction) |