Description
s:clear_matches() in autoload/css_color.vim calls matchdelete() on stored IDs without checking whether they still exist, causing E803: ID not found when another plugin or autocommand has already cleared the matches.
Steps to Reproduce
- Have NERDTree (or any other plugin that triggers
BufWinLeave) installed
- Open a file with CSS colors
- Use NERDTree to navigate to another file
- Error is thrown:
Error detected while processing function nerdtree#ui_glue#invokeKeyMap[1]..78[18]..77[3]..<SNR>78_activateFileNode[1]..107[1]..123[3]..179[6]..180[17]..15[3]..
BufWinLeave Autocommands for "<buffer=8>"..function <SNR>148_clear_matches:
line 1:
E803: ID not found: 1027
Root Cause
In autoload/css_color.vim around line 206:
function! s:clear_matches()
call map(get(w:, 'css_color_match_id', []), 'matchdelete(v:val)')
let w:css_color_match_id = []
endfunction
The match IDs stored in w:css_color_match_id may have already been removed (e.g. by clearmatches() or another plugin), so matchdelete(v:val) throws E803.
This is the same class of bug as #42, which was fixed for s:update_matches but not for s:clear_matches.
Suggested Fix
Wrap the deletion in a try/catch:
function! s:clear_matches()
for l:id in get(w:, 'css_color_match_id', [])
try | call matchdelete(l:id) | catch /E803/ | endtry
endfor
let w:css_color_match_id = []
endfunction
Or validate against existing matches first:
function! s:clear_matches()
let l:existing = map(getmatches(), 'v:val.id')
for l:id in get(w:, 'css_color_match_id', [])
if index(l:existing, l:id) >= 0
call matchdelete(l:id)
endif
endfor
let w:css_color_match_id = []
endfunction
Description
s:clear_matches()inautoload/css_color.vimcallsmatchdelete()on stored IDs without checking whether they still exist, causingE803: ID not foundwhen another plugin or autocommand has already cleared the matches.Steps to Reproduce
BufWinLeave) installedRoot Cause
In
autoload/css_color.vimaround line 206:The match IDs stored in
w:css_color_match_idmay have already been removed (e.g. byclearmatches()or another plugin), somatchdelete(v:val)throws E803.This is the same class of bug as #42, which was fixed for
s:update_matchesbut not fors:clear_matches.Suggested Fix
Wrap the deletion in a try/catch:
Or validate against existing matches first: