From f428139a0f596e503e7a9df117f7e2a3e7e96748 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sun, 27 Nov 2011 15:35:56 +0000 Subject: [PATCH] remove custom highlights manually - not with matchclear() 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(). --- autoload/syntastic.vim | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/autoload/syntastic.vim b/autoload/syntastic.vim index 30d56b83..c5342aaa 100644 --- a/autoload/syntastic.vim +++ b/autoload/syntastic.vim @@ -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 = []