diff options
-rw-r--r-- | .vim/UltiSnips/ledger.snippets | 4 | ||||
-rw-r--r-- | .vim/after/plugin/ledger.vim | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/.vim/UltiSnips/ledger.snippets b/.vim/UltiSnips/ledger.snippets new file mode 100644 index 0000000..32dc1da --- /dev/null +++ b/.vim/UltiSnips/ledger.snippets @@ -0,0 +1,4 @@ +snippet new "create a tranasction of today" +`date +%Y-%m-%d` ${1} + ${2} +endsnippet diff --git a/.vim/after/plugin/ledger.vim b/.vim/after/plugin/ledger.vim index 1b81a63..feaae92 100644 --- a/.vim/after/plugin/ledger.vim +++ b/.vim/after/plugin/ledger.vim @@ -12,11 +12,29 @@ let g:ledger_date_format = '%Y-%m-%d' let g:ledger_extra_options = '' let g:ledger_main = expand('$LEDGER_FILE') +function! HLedgerEntry() abort + let l:output = systemlist(join(['hledger', 'print', '--match', getline('.')])) + " Filter out warnings + let l:output = filter(l:output, "v:val !~? '^Warning: '") + " Errors may occur + if v:shell_error + echomsg join(l:output) + return + endif + " Append output so we insert instead of overwrite, then delete line + call append('.', l:output) + normal! "_dd +endfunction + function! s:ledger_keymap() abort + " formatprg is used in vim-ledger. Thus equalprg is used here. + let &l:equalprg = 'hledger -f- print' + noremap { ?^\d<CR> noremap } /^\d<CR> - inoremap <silent> <buffer> <Tab> <C-r>=ledger#autocomplete_and_align()<CR> - vnoremap <silent> <buffer> <Tab> :LedgerAlign<CR> + + noremap <silent> <buffer> * :call ledger#transaction_state_toggle(line('.'), ' *!')<CR> + inoremap <silent> <buffer> <c-x><c-x> <c-o>:call HLedgerEntry()<CR> endfunction au FileType ledger call s:ledger_keymap() |