Skip to content

Commit

Permalink
Fix false positive multi-line string detection
Browse files Browse the repository at this point in the history
Sometimes it seems that when `=`ing over a block, Vim will sometimes
not re-highlight strings correctly until we have already ran
`searchpairpos`.  In this case, we implement a hacky workaround which
detects the false-positive and recovers from it.
  • Loading branch information
axvr committed Apr 28, 2023
1 parent d177b3b commit 51e6a43
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,32 @@ function! s:GetClojureIndent()
" Move cursor to the first column of the line we want to indent.
call cursor(v:lnum, 1)

" Improve accuracy of string detection when a newline is entered.
if empty(getline(v:lnum))
" Improves the accuracy of string detection when a newline is
" entered while in insert mode.
let strline = v:lnum - 1
let synname = s:GetSynIdName(strline, len(getline(strline)))
let synname = s:GetSynIdName(strline, strlen(getline(strline)))
else
let synname = s:GetSynIdName(v:lnum, 1)
endif

let s:best_match = ['top', [0, 0]]

if synname =~? 'string'
" Sometimes, string highlighting does not kick in correctly,
" until after this first "s:CheckPair" call, so we have to
" detect and attempt an automatic correction.
call s:CheckPair('str', '"', '"', function('<SID>NotStringDelimiter'))
let new_synname = s:GetSynIdName(v:lnum, 1)
if new_synname !=# synname
echoerr 'Misdetected string! Retrying...'
let s:best_match = ['top', [0, 0]]
let synname = new_synname
endif
endif

if synname =~? 'string'
" We already checked this above, so pass through this block.
elseif synname =~? 'regex'
call s:CheckPair('reg', '#\zs"', '"', function('<SID>NotRegexpDelimiter'))
else
Expand Down

0 comments on commit 51e6a43

Please sign in to comment.