File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -394,14 +394,6 @@ function! ledger#align_amount_at_cursor()
394
394
endif
395
395
endf !
396
396
397
- func ! ledger#entry ()
398
- " enter a new transaction based on the text in the current line.
399
- let l = line (' .' ) - 1 " Insert transaction at the current line (i.e., below the line above the current one)
400
- let query = getline (' .' )
401
- normal ! " _dd
402
- exec l . ' read !' g: ledger_bin ' -f' shellescape (expand (g: ledger_main )) ' entry' shellescape (query)
403
- endfunc
404
-
405
397
" Report generation {{{1
406
398
407
399
" Helper functions and variables {{{2
@@ -490,6 +482,22 @@ function! s:ledger_cmd(file, args)
490
482
endf
491
483
" }}}
492
484
485
+ " Use current line as input to ledger entry and replace with output. If there
486
+ " are errors, they are echoed instead.
487
+ func ! ledger#entry ()
488
+ let l: output = systemlist (s: ledger_cmd (g: ledger_main , join ([" entry" , getline (' .' )])))
489
+ " Filter out warnings
490
+ let l: output = filter (l: output , " v:val !~? '^Warning: '" )
491
+ " Errors may occur
492
+ if v: shell_error
493
+ echomsg join (l: output )
494
+ return
495
+ endif
496
+ " Append output so we insert instead of overwrite, then delete line
497
+ call append (' .' , l: output )
498
+ normal ! " _dd
499
+ endfunc
500
+
493
501
" Run an arbitrary ledger command and show the output in a new buffer. If
494
502
" there are errors, no new buffer is opened: the errors are displayed in a
495
503
" quickfix window instead.
You can’t perform that action at this time.
0 commit comments