Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
remove custom highlights manually - not with matchclear()
Browse files Browse the repository at this point in the history
Previously we were blowing away highlights that were added by other
plugins via matchadd(). To prevent this we now track all the ids of the
highlights groups we add and remove them explicitly with matchdelete().
  • Loading branch information
scrooloose committed Nov 27, 2011
1 parent 3c26740 commit f428139
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions autoload/syntastic.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,42 @@ function! syntastic#ErrorBalloonExpr()
endfunction

function! syntastic#HighlightErrors(errors, termfunc, ...)
call clearmatches()
call syntastic#ClearErrorHighlights()

let forcecb = a:0 && a:1
for item in a:errors
let group = item['type'] == 'E' ? 'SpellBad' : 'SpellCap'
if item['col'] && !forcecb
let lastcol = col([item['lnum'], '$'])
let lcol = min([lastcol, item['col']])
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
call syntastic#HighlightError(group, '\%'.item['lnum'].'l\%'.lcol.'c')
else
let term = a:termfunc(item)
if len(term) > 0
call matchadd(group, '\%' . item['lnum'] . 'l' . term)
call syntastic#HighlightError(group, '\%' . item['lnum'] . 'l' . term)
endif
endif
endfor
endfunction

function! syntastic#ClearErrorHighlights()
for i in syntastic#ErrorHighlightIds()
call matchdelete(i)
endfor
let b:syntastic_error_highlight_ids = []
endfunction

function! syntastic#HighlightError(group, pattern)
call add(syntastic#ErrorHighlightIds(), matchadd(a:group, a:pattern))
endfunction

function! syntastic#ErrorHighlightIds()
if !exists("b:syntastic_error_highlight_ids")
let b:syntastic_error_highlight_ids = []
endif
return b:syntastic_error_highlight_ids
endfunction

" initialize c/cpp syntax checker handlers
function! s:Init()
let s:handlers = []
Expand Down

0 comments on commit f428139

Please sign in to comment.