diff options
author | Johann Klähn <kljohann@gmail.com> | 2010-09-07 21:05:08 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2010-09-07 21:05:08 +0200 |
commit | 2dff4dea3f27084c4daad5c6f89201eea7b4036b (patch) | |
tree | 0d9deb87b7786954cc2ec1dd4661601e44d477cd /contrib/vim/ftplugin/ledger.vim | |
parent | 04f564f01c9395188c1bc0d890745ad15eb3fc2f (diff) | |
download | fork-ledger-2dff4dea3f27084c4daad5c6f89201eea7b4036b.tar.gz fork-ledger-2dff4dea3f27084c4daad5c6f89201eea7b4036b.tar.bz2 fork-ledger-2dff4dea3f27084c4daad5c6f89201eea7b4036b.zip |
vim. add function to change item state ~ reconcile
To try this, map or call the following function:
LedgerSetTransactionState('') – removes state
LedgerSetTransactionState('*') – sets 'checked' state
…
The logic used to distinguish the different parts
of the first line of a transaction is rather basic
but proved to work so far.
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 c5354508..665fc6f1 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -270,6 +270,41 @@ endf "}}} " Helper functions {{{1 +function! LedgerSetTransactionState(char) + " modifies or sets the state of the transaction at the cursor, + " removing the state alltogether if a:char is empty + let head = search('^\d\S\+', 'bcnW') + if ! head + return + endif + + let parts = split(getline(head), '\s\+') + + let result = [] + while 1 + let part = remove(parts, 0) + " add state after date or (code) + if part =~ '^\d' || part =~ '^([^)]*)$' + call add(result, part) + " replace existing state with new state + elseif part =~ '^[!?*]$' + if ! empty(a:char) + call add(result, a:char) + endif + break + " add state in front of anything else if it does not exist yet + else + if ! empty(a:char) + call add(result, a:char) + endif + call add(result, part) + break + end + endwhile + + call setline(head, join(extend(result, parts))) +endf + " return length of string with fix for multibyte characters function! s:multibyte_strlen(text) "{{{2 return strlen(substitute(a:text, ".", "x", "g")) |