vim. add LedgerToggleTransactionState()
By using
call LedgerToggleTransactionState(line('.'), ' *?')
the state of the transaction will toggle through:
no state -> * -> ? -> no state -> …
beginning at what ever state it currently has.
Adjust to your liking.
Thanks to Chad Voegele for the suggestion.
This commit is contained in:
parent
58fcb0f30f
commit
6c0ccd5ffd
1 changed files with 31 additions and 6 deletions
|
|
@ -268,6 +268,26 @@ function! LedgerGetTags() "{{{1
|
||||||
return alltags
|
return alltags
|
||||||
endf "}}}
|
endf "}}}
|
||||||
|
|
||||||
|
function! LedgerToggleTransactionState(lnum, ...)
|
||||||
|
if a:0 == 1
|
||||||
|
let chars = a:1
|
||||||
|
else
|
||||||
|
let chars = ' *'
|
||||||
|
endif
|
||||||
|
let trans = s:transaction.from_lnum(a:lnum)
|
||||||
|
if empty(trans)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let old = has_key(trans, 'state') ? trans['state'] : ' '
|
||||||
|
let i = stridx(chars, old) + 1
|
||||||
|
let new = chars[i > len(chars) ? 0 : i]
|
||||||
|
|
||||||
|
call trans.set_state(new)
|
||||||
|
|
||||||
|
call setline(trans['head'], trans.format_head())
|
||||||
|
endf
|
||||||
|
|
||||||
function! LedgerSetTransactionState(lnum, char) "{{{1
|
function! LedgerSetTransactionState(lnum, char) "{{{1
|
||||||
" modifies or sets the state of the transaction at the cursor,
|
" modifies or sets the state of the transaction at the cursor,
|
||||||
" removing the state alltogether if a:char is empty
|
" removing the state alltogether if a:char is empty
|
||||||
|
|
@ -276,11 +296,7 @@ function! LedgerSetTransactionState(lnum, char) "{{{1
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(a:char) && has_key(trans, 'state')
|
call trans.set_state(a:char)
|
||||||
call remove(trans, 'state')
|
|
||||||
else
|
|
||||||
let trans['state'] = a:char
|
|
||||||
endif
|
|
||||||
|
|
||||||
call setline(trans['head'], trans.format_head())
|
call setline(trans['head'], trans.format_head())
|
||||||
endf "}}}
|
endf "}}}
|
||||||
|
|
@ -351,7 +367,8 @@ function! s:transaction.from_lnum(lnum) dict "{{{2
|
||||||
let trans['date'] = part
|
let trans['date'] = part
|
||||||
elseif ! has_key(trans, 'code') && part =~ '^([^)]*)$'
|
elseif ! has_key(trans, 'code') && part =~ '^([^)]*)$'
|
||||||
let trans['code'] = part[1:-2]
|
let trans['code'] = part[1:-2]
|
||||||
elseif ! has_key(trans, 'state') && part =~ '^[!?*]$'
|
elseif ! has_key(trans, 'state') && part =~ '^.$'
|
||||||
|
" the first character by itself is assumed to be the state of the transaction.
|
||||||
let trans['state'] = part
|
let trans['state'] = part
|
||||||
else
|
else
|
||||||
call add(description, part)
|
call add(description, part)
|
||||||
|
|
@ -361,6 +378,14 @@ function! s:transaction.from_lnum(lnum) dict "{{{2
|
||||||
return trans
|
return trans
|
||||||
endf "}}}
|
endf "}}}
|
||||||
|
|
||||||
|
function! s:transaction.set_state(char) dict "{{{2
|
||||||
|
if has_key(self, 'state') && a:char =~ '^\s*$'
|
||||||
|
call remove(self, 'state')
|
||||||
|
else
|
||||||
|
let self['state'] = a:char
|
||||||
|
endif
|
||||||
|
endf "}}}
|
||||||
|
|
||||||
function! s:transaction.parse_body(...) dict "{{{2
|
function! s:transaction.parse_body(...) dict "{{{2
|
||||||
if a:0 == 2
|
if a:0 == 2
|
||||||
let head = a:1
|
let head = a:1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue