summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorJohann Klähn <kljohann@gmail.com>2010-09-08 17:34:38 +0200
committerJohann Klähn <kljohann@gmail.com>2010-09-08 17:34:38 +0200
commite4060eb4219dab5c787d1823e39bc6f77e06b018 (patch)
treeeb5cf2e989a3cbd0bd4a786380dea7fce34de19c /contrib
parenteea6f33a2e47913db11bfaeb3181cc2e4d05fddd (diff)
downloadfork-ledger-e4060eb4219dab5c787d1823e39bc6f77e06b018.tar.gz
fork-ledger-e4060eb4219dab5c787d1823e39bc6f77e06b018.tar.bz2
fork-ledger-e4060eb4219dab5c787d1823e39bc6f77e06b018.zip
vim. get transactions in a range of lines
Diffstat (limited to 'contrib')
-rw-r--r--contrib/vim/ftplugin/ledger.vim35
1 files changed, 35 insertions, 0 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim
index 72588712..4490f3e0 100644
--- a/contrib/vim/ftplugin/ledger.vim
+++ b/contrib/vim/ftplugin/ledger.vim
@@ -435,6 +435,41 @@ endf "}}}
" Helper functions {{{1
+function! s:get_transactions(...) "{{{2
+ if a:0 == 2
+ let lnum = a:1
+ let end = a:2
+ elseif a:0 == 0
+ let lnum = 1
+ let end = line('$')
+ else
+ throw "wrong number of arguments for get_transactions()"
+ return []
+ endif
+
+ " safe view / position
+ let view = winsaveview()
+ let fe = &foldenable
+ set nofoldenable
+
+ let transactions = []
+ call cursor(lnum, 0)
+ while lnum && lnum <= end
+ let trans = s:transaction.from_lnum(lnum)
+ if ! empty(trans)
+ call add(transactions, trans)
+ call cursor(trans['tail'], 0)
+ endif
+ let lnum = search('^[~[:digit:]]\S\+', 'cW')
+ endw
+
+ " restore view / position
+ let &foldenable = fe
+ call winrestview(view)
+
+ return transactions
+endf "}}}
+
function! s:get_transaction_extents(lnum) "{{{2
" safe view / position
let view = winsaveview()