@@ -484,25 +484,9 @@ function! s:quickfix_populate(data)
484
484
return
485
485
endf
486
486
487
- " Parse a list of ledger arguments and build a ledger command ready to be
488
- " executed.
489
- "
490
- " Note that %, # and < *at the start* of an item are expanded by Vim. If you
491
- " want to pass such characters to Ledger, escape them with a backslash.
492
- "
493
- " See also http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
494
- " See also https://groups.google.com/forum/#!topic/vim_use/4ZejMpt7TeU
495
- function ! s: ledger_cmd (arglist)
496
- let l: cmd = g: ledger_bin . ' ' . g: ledger_extra_options
497
- for l: part in a: arglist
498
- if l: part = ~ ' \v^[%#<]'
499
- let l: expanded_part = expand (l: part )
500
- let l: cmd .= ' ' . (l: expanded_part == " " ? l: part : shellescape (l: expanded_part ))
501
- else
502
- let l: cmd .= ' ' . l: part
503
- endif
504
- endfor
505
- return l: cmd
487
+ " Build a ledger command to process the given file.
488
+ function ! s: ledger_cmd (file , args )
489
+ return join ([g: ledger_bin , g: ledger_extra_options , ' -f' , shellescape (expand (a: file )), a: args ])
506
490
endf
507
491
" }}}
508
492
@@ -511,9 +495,10 @@ endf
511
495
" quickfix window instead.
512
496
"
513
497
" Parameters:
498
+ " file The file to be processed.
514
499
" args A string of Ledger command-line arguments.
515
- function ! ledger#report (args )
516
- let l: output = systemlist (s: ledger_cmd (split ( a: args) ))
500
+ function ! ledger#report (file , args )
501
+ let l: output = systemlist (s: ledger_cmd (a: file , a: args ))
517
502
if v: shell_error " If there are errors, show them in a quickfix/location list.
518
503
call s: quickfix_populate (l: output )
519
504
call s: quickfix_toggle (' Errors' , ' Unable to parse errors' )
@@ -540,14 +525,15 @@ endf
540
525
" Show an arbitrary register report in a quickfix list.
541
526
"
542
527
" Parameters:
528
+ " file The file to be processed
543
529
" args A string of Ledger command-line arguments.
544
- function ! ledger#register (args )
545
- let l: cmd = s: ledger_cmd (extend ([
530
+ function ! ledger#register (file , args )
531
+ let l: cmd = s: ledger_cmd (a: file , join ([
546
532
\ " register" ,
547
533
\ " --format='" . g: ledger_qf_register_format . " '" ,
548
- \ " --prepend-format='%(filename):%(beg_line) '"
549
- \ ], split ( a: args))
550
- \ )
534
+ \ " --prepend-format='%(filename):%(beg_line) '" ,
535
+ \ a: args
536
+ \ ]) )
551
537
call s: quickfix_populate (systemlist (l: cmd ))
552
538
call s: quickfix_toggle (' Register report' )
553
539
endf
@@ -557,35 +543,31 @@ endf
557
543
" The default is to use the value of g:ledger_main.
558
544
"
559
545
" Parameters:
546
+ " file The file to be processed
560
547
" account An account name (String)
561
548
" target_amount The target amount (Float)
562
- function ! ledger#reconcile (account, target_amount, ... )
563
- let l: file = (a: 0 > 0 ? a: 1 : g: ledger_main )
564
- let l: cmd = s: ledger_cmd ([
549
+ function ! ledger#reconcile (file , account, target_amount)
550
+ let l: cmd = s: ledger_cmd (a: file , join ([
565
551
\ " register" ,
566
- \ " -f" ,
567
- \ l: file ,
568
552
\ " --uncleared" ,
569
553
\ " --format='" . g: ledger_qf_reconcile_format . " '" ,
570
554
\ " --prepend-format='%(filename):%(beg_line) %(pending ? \" P\" : \" U\" ) '" ,
571
555
\ a: account
572
- \ ])
573
- let l: file = expand (l : file ) " Needed for #show_balance() later
556
+ \ ]))
557
+ let l: file = expand (a : file ) " Needed for #show_balance() later
574
558
call s: quickfix_populate (systemlist (l: cmd ))
575
559
if s: quickfix_toggle (" Reconcile " . a: account , " Nothing to reconcile" )
576
560
let g: ledger_target_amount = a: target_amount
577
561
" Show updated account balance upon saving, as long as the quickfix window is open
578
562
augroup reconcile
579
563
autocmd !
580
- execute " autocmd BufWritePost *.ldg,*.ledger call ledger#show_balance('" . a: account . " ','" . l: file . " ')"
564
+ execute " autocmd BufWritePost *.ldg,*.ledger call ledger#show_balance('" . l: file . " ','" . a: account . " ')"
581
565
autocmd BufWipeout <buffer> call <sid> finish_reconciling ()
582
566
augroup END
583
567
" Add refresh shortcut
584
568
execute " nnoremap <silent> <buffer> <c-l> :<c-u>call ledger#reconcile('"
585
- \ . a: account . " '," . string (a: target_amount ) . " ,'" . l: file . " ')<cr>"
586
- " We need to pass the file path explicitly because at this point we are in
587
- " the quickfix window
588
- call ledger#show_balance (a: account , l: file )
569
+ \ . l: file . " ','" . a: account . " '," . string (a: target_amount ) . " )<cr>"
570
+ call ledger#show_balance (l: file , a: account )
589
571
endif
590
572
endf
591
573
@@ -598,31 +580,25 @@ function! s:finish_reconciling()
598
580
endf
599
581
600
582
" Show the pending/cleared balance of an account.
601
- " This function has two optional parameters :
583
+ " This function has an optional parameter :
602
584
"
603
585
" a:1 An account name
604
- " a:2 A file path
605
586
"
606
- " If both arguments are provided, the balance is computed for the given
607
- " account using the specified file. If no file path is provided, the value of
608
- " g:ledger_main is used. If no account if given, the account in the current
609
- " line and the value of g:ledger_main are used.
610
- function ! ledger#show_balance (... )
587
+ " If no account if given, the account in the current line is used.
588
+ function ! ledger#show_balance (file , ... )
611
589
let l: account = a: 0 > 0 && ! empty (a: 1 ) ? a: 1 : matchstr (getline (' .' ), ' \m\( \|\t\)\zs\S.\{-}\ze\( \|\t\|$\)' )
612
590
if empty (l: account )
613
591
call s: error_message (' No account found' )
614
592
return
615
593
endif
616
- let l: cmd = s: ledger_cmd ([
594
+ let l: cmd = s: ledger_cmd (a: file , join ( [
617
595
\ " cleared" ,
618
596
\ l: account ,
619
597
\ " --empty" ,
620
598
\ " --collapse" ,
621
- \ " -f" ,
622
- \ (a: 0 > 1 ? a: 2 : g: ledger_main ),
623
599
\ " --format='%(scrub(get_at(display_total, 0)))|%(scrub(get_at(display_total, 1)))|%(quantity(scrub(get_at(display_total, 1))))'" ,
624
600
\ (empty (g: ledger_default_commodity ) ? ' ' : " -X " . shellescape (g: ledger_default_commodity ))
625
- \ ])
601
+ \ ]))
626
602
let l: output = systemlist (l: cmd )
627
603
" Errors may occur, for example, when the account has multiple commodities
628
604
" and g:ledger_default_commodity is empty.
0 commit comments