From 66b39c46d1cff25c5191c3a55dd14e9414413dca Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Wed, 8 Sep 2010 10:01:44 +0200 Subject: 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') --- contrib/vim/ftplugin/ledger.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'contrib/vim/ftplugin/ledger.vim') 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) -- cgit v1.2.3