@@ -333,9 +333,11 @@ function! s:findall(text, rx)
333
333
endf
334
334
335
335
" Move the cursor to the specified column, filling the line with spaces if necessary.
336
- function ! s: goto_col (pos)
337
- exec " normal!" a: pos . " |"
338
- let diff = a: pos - virtcol (' .' )
336
+ " Ensure that at least min_spaces are added, and go to the end of the line if
337
+ " the line is already too long
338
+ function ! s: goto_col (pos, min_spaces)
339
+ exec " normal!" " $"
340
+ let diff = max ([a: min_spaces , a: pos - virtcol (' .' )])
339
341
if diff > 0 | exec " normal!" diff . " a " | endif
340
342
endf
341
343
@@ -373,19 +375,21 @@ function! ledger#align_commodity()
373
375
if rhs != ' '
374
376
" Remove everything after the account name (including spaces):
375
377
.s /\m^\s\+[^[:space:]].\{-}\zs\(\t\| \).*$/ /
376
- if g: ledger_decimal_sep == ' '
377
- let pos = matchend (rhs, ' \m\d[^[:space:]]*' )
378
- else
378
+ let pos = -1
379
+ if g: ledger_decimal_sep != ' '
379
380
" Find the position of the first decimal separator:
380
381
let pos = s: strpos (rhs, ' \V' . g: ledger_decimal_sep )
381
382
endif
383
+ if pos < 0
384
+ " Find the position after the first digits
385
+ let pos = matchend (rhs, ' \m\d[^[:space:]]*' )
386
+ endif
382
387
" Go to the column that allows us to align the decimal separator at g:ledger_align_at:
383
388
if pos > 0
384
- call s: goto_col (g: ledger_align_at - pos - 1 )
389
+ call s: goto_col (g: ledger_align_at - pos - 1 , 2 )
385
390
else
386
- call s: goto_col (g: ledger_align_at - strdisplaywidth (rhs) - 2 )
387
- endif
388
- " Append the part of the line that was previously removed:
391
+ call s: goto_col (g: ledger_align_at - strdisplaywidth (rhs) - 2 , 2 )
392
+ endif " Append the part of the line that was previously removed:
389
393
exe ' normal! a' . rhs
390
394
endif
391
395
endf !
@@ -401,11 +405,11 @@ function! ledger#align_amount_at_cursor()
401
405
endif
402
406
" Paste text at the correct column and append/prepend default commodity:
403
407
if g: ledger_commodity_before
404
- call s: goto_col (g: ledger_align_at - pos - len (g: ledger_default_commodity ) - len (g: ledger_commodity_sep ) - 1 )
408
+ call s: goto_col (g: ledger_align_at - pos - len (g: ledger_default_commodity ) - len (g: ledger_commodity_sep ) - 1 , 2 )
405
409
exe ' normal! a' . g: ledger_default_commodity . g: ledger_commodity_sep
406
410
normal ! p
407
411
else
408
- call s: goto_col (g: ledger_align_at - pos - 1 )
412
+ call s: goto_col (g: ledger_align_at - pos - 1 , 2 )
409
413
exe ' normal! pa' . g: ledger_commodity_sep . g: ledger_default_commodity
410
414
endif
411
415
endf !
0 commit comments