Skip to content
Merged
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
18 changes: 14 additions & 4 deletions autoload/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,20 @@ endf

" Return character position of decimal separator (multibyte safe)
function! s:decimalpos(expr) abort
let pos = match(a:expr, '\V' . g:ledger_decimal_sep)
if pos > 0
let pos = strchars(a:expr[:pos]) - 1
endif
" Remove trailing comments
let l:expr = substitute(a:expr, '\v +;.*$', '', '')
" Find first or last possible decimal separator candidate
if g:ledger_align_last
let pos = matchend(l:expr, '\v.*[' . g:ledger_decimal_sep . ']')
if pos > 0
let pos = strchars(a:expr[:pos]) + 1
endif
else
let pos = match(l:expr, '\v[' . g:ledger_decimal_sep . ']')
if pos > 0
let pos = strchars(a:expr[:pos]) - 1
endif
end
return pos
endf

Expand Down
14 changes: 13 additions & 1 deletion doc/ledger.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ Tips and useful commands
being the current line.

The decimal separator can be set using `g:ledger_decimal_sep`. The default
value of `g:ledger_decimal_sep` is `'.'`.
value of `g:ledger_decimal_sep` is `'.'`. More than one possible character
may be specified and any matches will count, e.g. `'.,'`.

By default the alignment is done on the first matching decimal separator.
This may be changed by setting `g:ledger_align_last` to `v:true`, in which
case the last possible decimal separater will be used. This is useful for
mixed-currency ledgers where decimal and thousands separators in different
currencies may clash and/or aligning on the right hand side of rate
convesions is desired.

See below for the recommended mappings.

Expand Down Expand Up @@ -324,6 +332,10 @@ behaviour of the ledger filetype.

let g:ledger_decimal_sep = '.'

* Specify alignment on first or last matching separator:

let g:ledger_align_last = v:false

* Specify at which column decimal separators should be aligned:

let g:ledger_align_at = 60
Expand Down
4 changes: 4 additions & 0 deletions ftplugin/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if !exists('g:ledger_decimal_sep')
let g:ledger_decimal_sep = '.'
endif

if !exists('g:ledger_align_last')
let g:ledger_align_last = v:false
endif

if !exists('g:ledger_align_at')
let g:ledger_align_at = 60
endif
Expand Down