Skip to content

Commit 6d12e23

Browse files
committed
refactor: Use more expressive and consistend variable names
1 parent 5bdd863 commit 6d12e23

2 files changed

Lines changed: 63 additions & 63 deletions

File tree

autoload/ledger.vim

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@ function! s:transaction.parse_body(...) abort dict
478478
return []
479479
endif
480480

481-
let lnum = head
481+
let line_number = head
482482
let tags = {}
483483
let postings = []
484-
while lnum <= tail
485-
let line = split(getline(lnum), '\s*\%(\t\| \);', 1)
484+
while line_number <= tail
485+
let line = split(getline(line_number), '\s*\%(\t\| \);', 1)
486486

487487
if line[0] =~# '^\s\+[^[:blank:];]'
488488
" posting
@@ -511,18 +511,18 @@ function! s:transaction.parse_body(...) abort dict
511511
let comment = join(line[1:], ' ;')
512512
if comment =~# '^\s*:'
513513
" tags without values
514-
for t in s:findall(comment, ':\zs[^:[:blank:]]\([^:]*[^:[:blank:]]\)\?\ze:')
515-
let tag_container[t] = ''
514+
for tag in s:findall(comment, ':\zs[^:[:blank:]]\([^:]*[^:[:blank:]]\)\?\ze:')
515+
let tag_container[tag] = ''
516516
endfor
517517
elseif comment =~# '^\s*[^:[:blank:]][^:]\+:'
518518
" tag with value
519519
let key = matchstr(comment, '^\s*\zs[^:]\+\ze:')
520520
if ! empty(key)
521-
let val = matchstr(comment, ':\s*\zs.*\ze\s*$')
522-
let tag_container[key] = val
521+
let value = matchstr(comment, ':\s*\zs.*\ze\s*$')
522+
let tag_container[key] = value
523523
endif
524524
endif
525-
let lnum += 1
525+
let line_number += 1
526526
endwhile
527527
return [tags, postings]
528528
endfunction
@@ -667,19 +667,19 @@ function! s:goto_col(pos, min_spaces) abort
667667
endfunction
668668

669669
" Return character position of decimal separator (multibyte safe)
670-
function! s:decimalpos(expr) abort
670+
function! s:decimal_position(expression) abort
671671
" Remove trailing comments
672-
let l:expr = substitute(a:expr, '\v +;.*$', '', '')
672+
let l:expr = substitute(a:expression, '\v +;.*$', '', '')
673673
" Find first or last possible decimal separator candidate
674674
if b:ledger_align_last
675675
let pos = matchend(l:expr, '\v.*[' . b:ledger_decimal_sep . ']')
676676
if pos > 0
677-
let pos = strchars(a:expr[:pos]) + 1
677+
let pos = strchars(a:expression[:pos]) + 1
678678
endif
679679
else
680680
let pos = match(l:expr, '\v[' . b:ledger_decimal_sep . ']')
681681
if pos > 0
682-
let pos = strchars(a:expr[:pos]) - 1
682+
let pos = strchars(a:expression[:pos]) - 1
683683
endif
684684
endif
685685
return pos
@@ -716,7 +716,7 @@ function! ledger#align_commodity() abort
716716
let pos = 0
717717
elseif b:ledger_decimal_sep !=# ''
718718
" Find the position of the first decimal separator:
719-
let pos = s:decimalpos(rhs)
719+
let pos = s:decimal_position(rhs)
720720
endif
721721
if pos < 0
722722
" Find the position after the first digits
@@ -753,7 +753,7 @@ function! ledger#align_amount_at_cursor() abort
753753
" Select and cut text:
754754
normal! viWd
755755
" Find the position of the decimal separator
756-
let pos = s:decimalpos(@") " Returns zero when the separator is the empty string
756+
let pos = s:decimal_position(@") " Returns zero when the separator is the empty string
757757
if pos <= 0
758758
let pos = len(@")
759759
endif

ftplugin/ledger.vim

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,37 @@ highlight default link LedgerPending Todo
4343
highlight default link LedgerTarget Statement
4444
highlight default link LedgerImproperPerc Special
4545

46-
let s:cursym = '[[:alpha:]¢$€£]\+'
47-
let s:valreg = '\('.
46+
let s:currency_symbol = '[[:alpha:]¢$€£]\+'
47+
let s:value_regex = '\('.
4848
\ '\%([0-9]\+\)'.
4949
\ '\%([,.][0-9]\+\)*'.
5050
\ '\|'.
5151
\ '[,.][0-9]\+'.
5252
\ '\)'
53-
let s:optsgn = '[+-]\?'
54-
let s:cursgn = '\('.
55-
\ s:optsgn.
53+
let s:optional_sign = '[+-]\?'
54+
let s:currency_sign = '\('.
55+
\ s:optional_sign.
5656
\ '\s*'.
57-
\ s:cursym.
57+
\ s:currency_symbol.
5858
\ '\|'.
59-
\ s:cursym.
59+
\ s:currency_symbol.
6060
\ '\s*'.
61-
\ s:optsgn.
61+
\ s:optional_sign.
6262
\ '\)'
6363

64-
let s:optional_balance_assertion = '\(\s*=\s*'.s:cursgn.'\s*'.s:valreg.'\)\?'
64+
let s:optional_balance_assertion = '\(\s*=\s*'.s:currency_sign.'\s*'.s:value_regex.'\)\?'
6565

66-
let s:rx_amount = s:valreg.
66+
let s:rx_amount = s:value_regex.
6767
\ s:optional_balance_assertion.
68-
\ '\s*\%('.s:cursym.'\s*\)\?'.
68+
\ '\s*\%('.s:currency_symbol.'\s*\)\?'.
6969
\ '\%(\s*;.*\)\?$'
7070

7171
function! LedgerFoldText()
7272
" find amount
7373
let amount = ''
74-
let lnum = v:foldstart + 1
75-
while lnum <= v:foldend
76-
let line = getline(lnum)
74+
let line_number = v:foldstart + 1
75+
while line_number <= v:foldend
76+
let line = getline(line_number)
7777

7878
" Skip metadata/leading comment
7979
if line !~# '^\%(\s\+;\|\d\)'
@@ -84,7 +84,7 @@ function! LedgerFoldText()
8484
break
8585
endif
8686
endif
87-
let lnum += 1
87+
let line_number += 1
8888
endwhile
8989

9090
" strip whitespace at beginning and end of line
@@ -143,55 +143,55 @@ endfunction
143143

144144
function! LedgerComplete(findstart, base)
145145
if a:findstart
146-
let lnum = line('.')
146+
let line_number = line('.')
147147
let line = getline('.')
148-
let b:compl_context = ''
148+
let b:completion_context = ''
149149
if line =~# '^\s\+[^[:blank:];]'
150150
" only allow completion when in or at end of account name
151151
if matchend(line, '^\s\+\%(\S \S\|\S\)\+') >= col('.') - 1
152152
" the start of the first non-blank character
153153
" (excluding virtual-transaction and 'cleared' marks)
154154
" is the beginning of the account name
155-
let b:compl_context = 'account'
155+
let b:completion_context = 'account'
156156
return matchend(line, '^\s\+[*!]\?\s*[\[(]\?')
157157
endif
158158
elseif line =~# '^account '
159-
let pre = matchend(line, '^account ')
160-
let b:compl_context = 'account'
161-
return pre
159+
let prefix = matchend(line, '^account ')
160+
let b:completion_context = 'account'
161+
return prefix
162162
elseif line =~# '^\d'
163-
let pre = matchend(line, '^\d\S\+\%\(\s\(([^\)]*)\|[*?!]\)\)\?\s\+')
164-
if pre <= col('.') - 1
165-
let b:compl_context = 'description'
166-
if pre == -1
163+
let prefix = matchend(line, '^\d\S\+\%\(\s\(([^\)]*)\|[*?!]\)\)\?\s\+')
164+
if prefix <= col('.') - 1
165+
let b:completion_context = 'description'
166+
if prefix == -1
167167
return -3
168168
endif
169-
return pre
169+
return prefix
170170
endif
171171
elseif b:ledger_is_hledger && line =~# '^payee '
172-
let pre = matchend(line, '^payee ')
173-
let b:compl_context = 'description'
174-
return pre
172+
let prefix = matchend(line, '^payee ')
173+
let b:completion_context = 'description'
174+
return prefix
175175
elseif line =~# '^$'
176-
let b:compl_context = 'new'
176+
let b:completion_context = 'new'
177177
return 0
178178
endif
179179
return -3
180180
else
181-
if ! exists('b:compl_cache')
182-
let b:compl_cache = s:collect_completion_data()
183-
let b:compl_cache['#'] = changenr()
181+
if ! exists('b:completion_cache')
182+
let b:completion_cache = s:collect_completion_data()
183+
let b:completion_cache['#'] = changenr()
184184
endif
185185
let update_cache = 0
186186

187187
let results = []
188-
if b:compl_context ==# 'account'
188+
if b:completion_context ==# 'account'
189189
let hierarchy = split(a:base, ':')
190190
if a:base =~# ':$'
191191
call add(hierarchy, '')
192192
endif
193193

194-
let results = ledger#find_in_tree(b:compl_cache.accounts, hierarchy)
194+
let results = ledger#find_in_tree(b:completion_cache.accounts, hierarchy)
195195
let exacts = filter(copy(results), 'v:val[1]')
196196

197197
if len(exacts) < 1
@@ -206,19 +206,19 @@ function! LedgerComplete(findstart, base)
206206
call map(results, 'v:val[0]')
207207

208208
if b:ledger_fuzzy_account_completion
209-
let results = matchfuzzy(b:compl_cache.flat_accounts, a:base, {'matchseq':1})
209+
let results = matchfuzzy(b:completion_cache.flat_accounts, a:base, {'matchseq':1})
210210
elseif b:ledger_detailed_first
211211
let results = reverse(sort(results, 's:sort_accounts_by_depth'))
212212
else
213213
let results = sort(results)
214214
endif
215-
elseif b:compl_context ==# 'description'
216-
let results = ledger#filter_items(b:compl_cache.descriptions, a:base)
215+
elseif b:completion_context ==# 'description'
216+
let results = ledger#filter_items(b:completion_cache.descriptions, a:base)
217217

218218
if len(results) < 1
219219
let update_cache = 1
220220
endif
221-
elseif b:compl_context ==# 'new'
221+
elseif b:completion_context ==# 'new'
222222
return [strftime(b:ledger_date_format)]
223223
endif
224224

@@ -228,11 +228,11 @@ function! LedgerComplete(findstart, base)
228228
endif
229229

230230
" no completion (apart from a:base) found. update cache if file has changed
231-
if update_cache && b:compl_cache['#'] != changenr()
232-
unlet b:compl_cache
231+
if update_cache && b:completion_cache['#'] != changenr()
232+
unlet b:completion_cache
233233
return LedgerComplete(a:findstart, a:base)
234234
else
235-
unlet! b:compl_context
235+
unlet! b:completion_context
236236
return results
237237
endif
238238
endif
@@ -246,9 +246,9 @@ function! s:collect_completion_data()
246246
let cache.flat_accounts = accounts
247247
let cache.descriptions = s:get_descriptions_list()
248248

249-
for xact in transactions
250-
let [t, postings] = xact.parse_body()
251-
let tagdicts = [t]
249+
for transaction in transactions
250+
let [tags, postings] = transaction.parse_body()
251+
let tagdicts = [tags]
252252

253253
" collect account names (only when not using ledger binary)
254254
if b:ledger_bin ==# v:false
@@ -345,15 +345,15 @@ function! s:count_expression(text, expression)
345345
return len(split(a:text, a:expression, 1))-1
346346
endfunction
347347

348-
function! s:autocomplete_account_or_payee(argLead, cmdLine, cursorPos)
349-
if a:argLead =~# '^@'
348+
function! s:autocomplete_account_or_payee(argument_lead, command_line, cursor_position)
349+
if a:argument_lead =~# '^@'
350350
let payees = s:get_descriptions_list()
351-
let pattern = strpart(a:argLead, 1)
351+
let pattern = strpart(a:argument_lead, 1)
352352
return map(filter(payees, "v:val =~? '" . pattern . "' && v:val !~? '^Warning: '"),
353353
\ '"@" . escape(v:val, " ")')
354354
else
355355
let accounts = s:get_accounts_list()
356-
return map(filter(accounts, "v:val =~? '" . a:argLead . "' && v:val !~? '^Warning: '"),
356+
return map(filter(accounts, "v:val =~? '" . a:argument_lead . "' && v:val !~? '^Warning: '"),
357357
\ 'escape(v:val, " ")')
358358
endif
359359
endfunction

0 commit comments

Comments
 (0)