summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohann Klähn <kljohann@gmail.com>2009-06-25 18:27:07 +0200
committerJohann Klähn <kljohann@gmail.com>2009-06-29 16:41:35 +0200
commit84e6a6e926effcb53148e8d0b0d4b5b79d8914c2 (patch)
tree31310e96fa93c2fa15dfea73d612d885494315b8
parenta853a1c59a8806b5511b292a8a5fcf6af84515df (diff)
downloadfork-ledger-84e6a6e926effcb53148e8d0b0d4b5b79d8914c2.tar.gz
fork-ledger-84e6a6e926effcb53148e8d0b0d4b5b79d8914c2.tar.bz2
fork-ledger-84e6a6e926effcb53148e8d0b0d4b5b79d8914c2.zip
vim. list 'deeper' entries first (completion)
-rw-r--r--contrib/vim/ftplugin/ledger.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim
index 698a5929..4b1c3a5d 100644
--- a/contrib/vim/ftplugin/ledger.vim
+++ b/contrib/vim/ftplugin/ledger.vim
@@ -38,6 +38,30 @@ if !exists('g:ledger_fillstring')
let g:ledger_fillstring = ' '
endif
+" If enabled this will list the most detailed matches at the top {{{
+" of the completion list.
+" For example when you have some accounts like this:
+" A:Ba:Bu
+" A:Bu:Bu
+" and you complete on A:B:B normal behaviour may be the following
+" A:B:B
+" A:Bu:Bu
+" A:Bu
+" A:Ba:Bu
+" A:Ba
+" A
+" with this option turned on it will be
+" A:B:B
+" A:Bu:Bu
+" A:Ba:Bu
+" A:Bu
+" A:Ba
+" A
+" }}}
+if !exists('g:ledger_detailed_first')
+ let g:ledger_detailed_first = 0
+endif
+
let s:rx_amount = '\('.
\ '\%([0-9]\+\)'.
\ '\%([,.][0-9]\+\)*'.
@@ -152,6 +176,11 @@ function! LedgerComplete(findstart, base) "{{{1
endif
let results = LedgerFindInTree(LedgerGetAccountHierarchy(), hierarchy)
+ " sort by alphabet and reverse because it will get reversed one more time
+ let results = reverse(sort(results))
+ if g:ledger_detailed_first
+ let results = sort(results, 's:sort_accounts_by_depth')
+ endif
call add(results, a:base)
return reverse(results)
elseif b:compl_context == 'meta-tag' "{{{2
@@ -260,3 +289,13 @@ function! s:grep_buffer(expression) "{{{2
let lines = map(getline(1, '$'), 'matchstr(v:val, '''.a:expression.''')')
return filter(lines, 'v:val != ""')
endf "}}}
+
+function! s:sort_accounts_by_depth(name1, name2) "{{{2
+ let depth1 = s:count_expression(a:name1, ':')
+ let depth2 = s:count_expression(a:name2, ':')
+ return depth1 == depth2 ? 0 : depth1 > depth2 ? 1 : -1
+endf "}}}
+
+function! s:count_expression(text, expression) "{{{2
+ return len(split(a:text, a:expression, 1))-1
+endf "}}}