File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,50 @@ endf "}}}
267
267
268
268
" == helper functions ==
269
269
270
+ " get a list of declared accounts in the buffer
271
+ function ! ledger#declared_accounts (... )
272
+ if a: 0 == 2
273
+ let lnum = a: 1
274
+ let lend = a: 2
275
+ elseif a: 0 == 0
276
+ let lnum = 1
277
+ let lend = line (' $' )
278
+ else
279
+ throw " wrong number of arguments for ledger#declared_accounts()"
280
+ return []
281
+ endif
282
+
283
+ " save view / position
284
+ let view = winsaveview ()
285
+ let fe = &foldenable
286
+ set nofoldenable
287
+
288
+ let accounts = []
289
+ call cursor (lnum, 0 )
290
+ while 1
291
+ let lnum = search (' ^account\s' , ' cW' , lend)
292
+ if ! lnum || lnum > lend
293
+ break
294
+ endif
295
+
296
+ " remove comments at the end and "account" at the front
297
+ let line = split (getline (lnum), ' \s\+;' )[0 ]
298
+ let line = matchlist (line , ' account\s\+\(.\+\)' )[1 ]
299
+
300
+ if len (line ) > 1
301
+ call add (accounts, line )
302
+ endif
303
+
304
+ call cursor (lnum+ 1 ,0 )
305
+ endw
306
+
307
+ " restore view / position
308
+ let &foldenable = fe
309
+ call winrestview (view )
310
+
311
+ return accounts
312
+ endf
313
+
270
314
function ! s: get_transaction_extents (lnum)
271
315
if ! (indent (a: lnum ) || getline (a: lnum ) = ~ ' ^[~=[:digit:]]' )
272
316
" only do something if lnum is in a transaction
Original file line number Diff line number Diff line change @@ -333,7 +333,7 @@ unlet s:old s:new s:fun
333
333
function ! s: collect_completion_data () " {{{1
334
334
let transactions = ledger#transactions ()
335
335
let cache = {' descriptions' : [], ' tags' : {}, ' accounts' : {}}
336
- let accounts = []
336
+ let accounts = ledger#declared_accounts ()
337
337
for xact in transactions
338
338
" collect descriptions
339
339
if has_key (xact, ' description' ) && index (cache.descriptions, xact[' description' ]) < 0
You can’t perform that action at this time.
0 commit comments