Skip to content

Commit

Permalink
Small refactor to improve code clarity in indentation code
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed May 1, 2023
1 parent bdbc281 commit 437e727
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,23 @@ function! s:InsideForm(lnum)
" Reduce tokens from line "lnum" into "tokens".
for tk in s:TokeniseLine(lnum)
if tk[0] ==# '"'
" Keep track of the first string delimiter we
" see, as we'll need it later for multi-line
" strings/regexps.
if first_string_pos == []
let first_string_pos = tk[1]
endif

if ! empty(tokens) && tokens[-1][0] ==# '"'
if in_string
let in_string = 0
call remove(tokens, -1)
else
let in_string = 1
call add(tokens, tk)
endif

continue
endif

" When in string ignore other tokens.
if in_string | continue | endif

if ! empty(tokens) && get(s:pairs, tk[0], '') ==# tokens[-1][0]
" Track the first string delimiter we
" see, as we may need it later for
" multi-line strings/regexps.
if first_string_pos == []
let first_string_pos = tk
endif
endif
elseif in_string
" When in string ignore other tokens.
elseif ! empty(tokens) && get(s:pairs, tk[0], '') ==# tokens[-1][0]
" Matching pair: drop the last item in tokens.
call remove(tokens, -1)
else
Expand All @@ -115,8 +110,6 @@ function! s:InsideForm(lnum)
endif
endfor

" echom 'Pass' lnum tokens

if ! empty(tokens) && has_key(s:pairs, tokens[0][0])
return tokens[0]
endif
Expand All @@ -127,7 +120,7 @@ function! s:InsideForm(lnum)
if ! empty(tokens) && tokens[0][0] ==# '"'
" Must have been in a multi-line string or regular expression
" as the string was never closed.
return ['"', first_string_pos]
return first_string_pos
endif

return ['^', [0, 0]] " Default to top-level.
Expand Down

0 comments on commit 437e727

Please sign in to comment.