Skip to content

Commit

Permalink
Refactor for DRY with explanitory comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jul 1, 2019
1 parent 56a3038 commit 31836bd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions autoload/ledger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ function! s:goto_col(pos, min_spaces)
if diff > 0 | exec "normal!" diff . "a " | endif
endf

" Return substring position (in chars).
function! s:strpos(expr, pat)
let pos = match(a:expr, a:pat)
" Return character position of decimal separator (multibyte safe)
function! s:decimalpos(expr)
let pos = match(a:expr, '\V' . g:ledger_decimal_sep)
if pos > 0
let pos = strchars(a:expr[:pos]) - 1
endif
Expand Down Expand Up @@ -378,7 +378,7 @@ function! ledger#align_commodity()
let pos = -1
if g:ledger_decimal_sep != ''
" Find the position of the first decimal separator:
let pos = s:strpos(rhs, '\V' . g:ledger_decimal_sep)
let pos = s:decimalpos(rhs)
endif
if pos < 0
" Find the position after the first digits
Expand All @@ -399,7 +399,7 @@ function! ledger#align_amount_at_cursor()
" Select and cut text:
normal! viWd
" Find the position of the decimal separator
let pos = s:strpos(@", '\V' . g:ledger_decimal_sep) " Returns zero when the separator is the empty string
let pos = s:decimalpos(@") " Returns zero when the separator is the empty string
if pos <= 0
let pos = len(@")
endif
Expand Down

0 comments on commit 31836bd

Please sign in to comment.