Skip to content

Commit

Permalink
Fix false-positive comment detection within strings
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed Aug 13, 2023
1 parent f3d889f commit bf4cf3d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,18 @@ function! s:TokeniseLine(line_num)
while 1
" We perform searches within the buffer (and move the cusor)
" for better performance than looping char by char in a line.
let token = searchpos('[()[\]{};"]', 'bW', a:line_num)
let token_pos = searchpos('[()[\]{};"]', 'bW', a:line_num)

" No more matches, exit loop.
if token == [0, 0] | break | endif
if token_pos == [0, 0] | break | endif

let t_idx = token[1] - 1
let t_idx = token_pos[1] - 1

" Escaped character, ignore.
if s:IsEscaped(ln, t_idx) | continue | endif
let t_char = ln[t_idx]
if t_char ==# ';'
" Comment found, reset the token list for this line.
let tokens = []
elseif t_char =~# '[()\[\]{}"]'
" Add token to the list.
call add(tokens, [t_char, token])
endif
" Add token to the list.
call add(tokens, [ln[t_idx], token_pos])
endwhile

return tokens
Expand Down Expand Up @@ -151,6 +145,9 @@ function! s:InsideForm(lnum)
endif
elseif in_string
" In string: ignore other tokens.
elseif tk[0] ==# ';'
" Comment: break loop.
break
elseif ! empty(tokens) && get(s:pairs, tk[0], '') ==# tokens[-1][0]
" Matching pair: drop the last item in tokens.
call remove(tokens, -1)
Expand Down

0 comments on commit bf4cf3d

Please sign in to comment.