From 3797df94c3470e1a8cacc074d46d850bf7cc8f77 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 29 Dec 2023 13:46:19 +0100 Subject: [PATCH] Fix for trailing CR character with omni completion. This issue manifests on Windows OS, because CRLF is used here for end of line and systemlist() function splits lines on LF cahracter. system() function takes care of OS specific end of line chars. --- autoload/ledger.vim | 10 +++++----- ftplugin/ledger.vim | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/autoload/ledger.vim b/autoload/ledger.vim index 3e49793..bff9579 100644 --- a/autoload/ledger.vim +++ b/autoload/ledger.vim @@ -671,7 +671,7 @@ endf " Use current line as input to ledger entry and replace with output. If there " are errors, they are echoed instead. function! ledger#entry() abort - let l:output = systemlist(s:ledger_cmd(g:ledger_main, join(['entry', getline('.')]))) + let l:output = split(system(s:ledger_cmd(g:ledger_main, join(['entry', getline('.')]))), '\n') " Filter out warnings let l:output = filter(l:output, "v:val !~? '^Warning: '") " Errors may occur @@ -695,7 +695,7 @@ endfunc " Returns: " Ledger's output as a String. function! ledger#report(file, args) abort - let l:output = systemlist(s:ledger_cmd(a:file, a:args)) + let l:output = split(system(s:ledger_cmd(a:file, a:args)), '\n') if v:shell_error " If there are errors, show them in a quickfix/location list. call s:quickfix_populate(l:output) call s:quickfix_toggle('Errors', 'Unable to parse errors') @@ -742,7 +742,7 @@ function! ledger#register(file, args) abort \ "--prepend-format='%(filename):%(beg_line) '", \ a:args \ ])) - call s:quickfix_populate(systemlist(l:cmd)) + call s:quickfix_populate(split(system(l:cmd), '\n')) call s:quickfix_toggle('Register report') endf @@ -761,7 +761,7 @@ function! ledger#reconcile(file, account, target_amount) abort \ shellescape(a:account) \ ])) let l:file = expand(a:file) " Needed for #show_balance() later - call s:quickfix_populate(systemlist(l:cmd)) + call s:quickfix_populate(split(system(l:cmd), '\n')) if s:quickfix_toggle('Reconcile ' . a:account, 'Nothing to reconcile') let g:ledger_target_amount = a:target_amount " Show updated account balance upon saving, as long as the quickfix window is open @@ -805,7 +805,7 @@ function! ledger#show_balance(file, ...) abort \ "--format='%(scrub(get_at(display_total, 0)))|%(scrub(get_at(display_total, 1)))|%(quantity(scrub(get_at(display_total, 1))))'", \ (empty(g:ledger_default_commodity) ? '' : '-X ' . shellescape(g:ledger_default_commodity)) \ ])) - let l:output = systemlist(l:cmd) + let l:output = split(system(l:cmd), '\n') " Errors may occur, for example, when the account has multiple commodities " and g:ledger_default_commodity is empty. if v:shell_error diff --git a/ftplugin/ledger.vim b/ftplugin/ledger.vim index 0a8581e..d65ab51 100644 --- a/ftplugin/ledger.vim +++ b/ftplugin/ledger.vim @@ -400,12 +400,12 @@ function! s:collect_completion_data() "{{{1 let transactions = ledger#transactions() let cache = {'descriptions': [], 'tags': {}, 'accounts': {}} if exists('g:ledger_accounts_cmd') - let accounts = systemlist(g:ledger_accounts_cmd) + let accounts = split(system(g:ledger_accounts_cmd), '\n') else let accounts = ledger#declared_accounts() endif if exists('g:ledger_descriptions_cmd') - let cache.descriptions = systemlist(g:ledger_descriptions_cmd) + let cache.descriptions = split(system(g:ledger_descriptions_cmd), '\n') endif for xact in transactions if !exists('g:ledger_descriptions_cmd') @@ -494,10 +494,10 @@ endf "}}} function! s:autocomplete_account_or_payee(argLead, cmdLine, cursorPos) "{{{2 return (a:argLead =~# '^@') ? - \ map(filter(systemlist(g:ledger_bin . ' -f ' . shellescape(expand(g:ledger_main)) . ' payees'), + \ map(filter(split(system(g:ledger_bin . ' -f ' . shellescape(expand(g:ledger_main)) . ' payees'), '\n'), \ "v:val =~? '" . strpart(a:argLead, 1) . "' && v:val !~? '^Warning: '"), '"@" . escape(v:val, " ")') \ : - \ map(filter(systemlist(g:ledger_bin . ' -f ' . shellescape(expand(g:ledger_main)) . ' accounts'), + \ map(filter(split(system(g:ledger_bin . ' -f ' . shellescape(expand(g:ledger_main)) . ' accounts'), '\n'), \ "v:val =~? '" . a:argLead . "' && v:val !~? '^Warning: '"), 'escape(v:val, " ")') endf "}}}