Skip to content

Commit b14c7f5

Browse files
author
Lifepillar
committed
Add g:ledger_extra_options.
The purpose of this variable is to allow the user to specify default options to pass to ledger when generating reports. Previously, such options would have to be included in `g:ledger_bin`, which would make it difficult to call ledger without including them (which in some cases is desirable, e.g., in `ledger#entry()` or when getting the list of payees or accounts). So, from now on `g:ledger_bin` is assumed to be the path to the ledger executable, without further options. The two global variables are now documented.
1 parent 7e76d0c commit b14c7f5

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

autoload/ledger.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ endf
493493
" See also http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
494494
" See also https://groups.google.com/forum/#!topic/vim_use/4ZejMpt7TeU
495495
function! s:ledger_cmd(arglist)
496-
let l:cmd = g:ledger_bin
496+
let l:cmd = g:ledger_bin . ' ' . g:ledger_extra_options
497497
for l:part in a:arglist
498498
if l:part =~ '\v^[%#<]'
499499
let l:expanded_part = expand(l:part)

compiler/ledger.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if exists(":CompilerSet") != 2
1313
endif
1414

1515
" default value will be set in ftplugin
16-
if ! exists("g:ledger_bin") || empty(g:ledger_bin) || ! executable(split(g:ledger_bin, '\s')[0])
16+
if ! exists("g:ledger_bin") || empty(g:ledger_bin) || ! executable(g:ledger_bin)
1717
finish
1818
endif
1919

@@ -25,5 +25,5 @@ CompilerSet errorformat+=%tarning:\ \"%f\"\\,\ line\ %l:\ %m
2525
CompilerSet errorformat+=%-G%.%#
2626

2727
" Check file syntax
28-
exe 'CompilerSet makeprg='.substitute(g:ledger_bin, ' ', '\\ ', 'g').'\ source\ %:S'
28+
exe 'CompilerSet makeprg='.substitute(g:ledger_bin, ' ', '\\ ', 'g').'\ '.substitute(g:ledger_extra_options, ' ', '\\ ', 'g').'\ source\ %:S'
2929

doc/ledger.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ Tips and useful commands
3737

3838
:silent make | redraw! | cwindow
3939

40-
It is recommended to set the value of `g:ledger_bin` (see below) as follows:
40+
It is recommended to set the value of `g:ledger_extra_options` (see below)
41+
as follows:
4142

42-
let g:ledger_bin = 'ledger --pedantic --explicit --check-payees'
43+
let g:ledger_extra_options = '--pedantic --explicit --check-payees'
4344

4445
to catch most potential problems in your source file.
4546

@@ -209,6 +210,14 @@ Configuration
209210
Include the following let-statements somewhere in your `.vimrc` to modify the
210211
behaviour of the ledger filetype.
211212

213+
* Path to the `ledger` executable:
214+
215+
let g:ledger_bin = 'ledger'
216+
217+
* Additional default options for the `ledger` executable:
218+
219+
let g:ledger_extra_options = ''
220+
212221
* Number of columns that will be used to display the foldtext. Set this when
213222
you think that the amount is too far off to the right.
214223

ftplugin/ledger.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setl commentstring=;%s
2121
setl omnifunc=LedgerComplete
2222

2323
" set location of ledger binary for checking and auto-formatting
24-
if ! exists("g:ledger_bin") || empty(g:ledger_bin) || ! executable(split(g:ledger_bin, '\s')[0])
24+
if ! exists("g:ledger_bin") || empty(g:ledger_bin) || ! executable(g:ledger_bin)
2525
if executable('ledger')
2626
let g:ledger_bin = 'ledger'
2727
else
@@ -37,6 +37,10 @@ if exists("g:ledger_bin")
3737
exe 'setl formatprg='.substitute(g:ledger_bin, ' ', '\\ ', 'g').'\ -f\ -\ print'
3838
endif
3939

40+
if !exists('g:ledger_extra_options')
41+
let g:ledger_extra_options = ''
42+
endif
43+
4044
" You can set a maximal number of columns the fold text (excluding amount)
4145
" will use by overriding g:ledger_maxwidth in your .vimrc.
4246
" When maxwidth is zero, the amount will be displayed at the far right side

0 commit comments

Comments
 (0)