Skip to content

Commit 31836bd

Browse files
committed
Refactor for DRY with explanitory comments
1 parent 56a3038 commit 31836bd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

autoload/ledger.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ function! s:goto_col(pos, min_spaces)
341341
if diff > 0 | exec "normal!" diff . "a " | endif
342342
endf
343343

344-
" Return substring position (in chars).
345-
function! s:strpos(expr, pat)
346-
let pos = match(a:expr, a:pat)
344+
" Return character position of decimal separator (multibyte safe)
345+
function! s:decimalpos(expr)
346+
let pos = match(a:expr, '\V' . g:ledger_decimal_sep)
347347
if pos > 0
348348
let pos = strchars(a:expr[:pos]) - 1
349349
endif
@@ -378,7 +378,7 @@ function! ledger#align_commodity()
378378
let pos = -1
379379
if g:ledger_decimal_sep != ''
380380
" Find the position of the first decimal separator:
381-
let pos = s:strpos(rhs, '\V' . g:ledger_decimal_sep)
381+
let pos = s:decimalpos(rhs)
382382
endif
383383
if pos < 0
384384
" Find the position after the first digits
@@ -399,7 +399,7 @@ function! ledger#align_amount_at_cursor()
399399
" Select and cut text:
400400
normal! viWd
401401
" Find the position of the decimal separator
402-
let pos = s:strpos(@", '\V' . g:ledger_decimal_sep) " Returns zero when the separator is the empty string
402+
let pos = s:decimalpos(@") " Returns zero when the separator is the empty string
403403
if pos <= 0
404404
let pos = len(@")
405405
endif

0 commit comments

Comments
 (0)