From 2dff4dea3f27084c4daad5c6f89201eea7b4036b Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Tue, 7 Sep 2010 21:05:08 +0200 Subject: vim. add function to change item state ~ reconcile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- 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 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")) -- cgit v1.2.3