Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autoload/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ function! ledger#output(report) abort
endif
" Open a new buffer to show Ledger's output.
execute get(s:winpos_map, b:ledger_winpos, 'bo new')
setlocal buftype=nofile bufhidden=wipe modifiable nobuflisted noswapfile nowrap
setlocal buftype=nofile bufhidden=wipe modifiable nobuflisted noswapfile nowrap nolist
call ledger#init()
call append(0, a:report)
setlocal nomodifiable
Expand Down
40 changes: 29 additions & 11 deletions ftplugin/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,34 @@ function! s:count_expression(text, expression)
return len(split(a:text, a:expression, 1))-1
endfunction

augroup refresh_autocomplete_account_or_payee_cache
au!
autocmd! CmdlineLeave * if exists('s:accounts_cache') | unlet s:accounts_cache | endif
autocmd! CmdlineLeave * if exists('s:payees_cache') | unlet s:payees_cache | endif
augroup END

function! s:autocomplete_account_or_payee(argument_lead, command_line, cursor_position)
if a:argument_lead =~# '^@'
let payees = s:get_descriptions_list()
let pattern = strpart(a:argument_lead, 1)
return map(filter(payees, "v:val =~? '" . pattern . "' && v:val !~? '^Warning: '"),
\ '"@" . escape(v:val, " ")')
if !exists('s:payees_cache')
let s:payees_cache = join(map(filter(s:get_descriptions_list(), "v:val !~? '^Warning: '"), '"@" .. v:val'), "\n")
endif
return s:payees_cache
else
if !exists('s:accounts_cache')
let s:accounts_cache = join(filter(s:get_accounts_list(), "v:val !~? '^Warning: '"), "\n")
endif
return s:accounts_cache
endif
endfunction

function! s:ledger_complete(argument_lead, command_line, cursor_position)
let parts = split(strpart(a:command_line, 0, a:cursor_position), '\s\+', 1)
if len(parts) == 2
return "accounts\nbalance\nbudget\ncleared\ncommodities\nconvert\ncsv\nentry\nemacs\nequity\npayees\npricemap\nprices\npricedb\nprint\npush\npop\nregister\nselect\nsource\nstats\nxml\n"
elseif len(parts) == 3 && parts[1] =~# 'accounts\|balance\|budget\|cleared\|commodities\|csv\|equity\|payees\|prices\|pricedb\|print\|register\|stats\|xml'
return s:autocomplete_account_or_payee(a:argument_lead, a:command_line, a:cursor_position)
else
let accounts = s:get_accounts_list()
return map(filter(accounts, "v:val =~? '" . a:argument_lead . "' && v:val !~? '^Warning: '"),
\ 'escape(v:val, " ")')
return ""
endif
endfunction

Expand All @@ -365,18 +383,18 @@ function! s:reconcile(file, account)
endfunction

" Commands
command! -buffer -nargs=? -complete=customlist,<SID>autocomplete_account_or_payee
command! -buffer -nargs=? -complete=custom,<SID>autocomplete_account_or_payee
\ Balance call ledger#show_balance(b:ledger_main, <q-args>)

command! -buffer -nargs=+ -complete=customlist,<SID>autocomplete_account_or_payee
command! -buffer -nargs=+ -complete=custom,<SID>ledger_complete
\ Ledger call ledger#output(ledger#report(b:ledger_main, <q-args>))

command! -buffer -range LedgerAlign <line1>,<line2>call ledger#align_commodity()

command! -buffer LedgerAlignBuffer call ledger#align_commodity_buffer()

command! -buffer -nargs=1 -complete=customlist,<SID>autocomplete_account_or_payee
command! -buffer -nargs=1 -complete=custom,<SID>autocomplete_account_or_payee
\ Reconcile call <SID>reconcile(b:ledger_main, <q-args>)

command! -buffer -complete=customlist,<SID>autocomplete_account_or_payee -nargs=*
command! -buffer -complete=custom,<SID>autocomplete_account_or_payee -nargs=*
\ Register call ledger#register(b:ledger_main, <q-args>)