Skip to content

Commit

Permalink
Poperly check for existing ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed Jun 30, 2022
1 parent 1b22dc5 commit a0a602e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugin/better-whitespace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,28 @@ else
function! s:HighlightEOLWhitespace()
call <SID>ClearHighlighting()
if <SID>ShouldHighlight()
let s:match_id = matchadd('ExtraWhitespace', s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
let w:better_whitespace_match_id = matchadd('ExtraWhitespace',
\ s:eol_whitespace_pattern, 10, get(w:, 'better_whitespace_match_id', -1))
endif
endfunction

" Match Whitespace on all lines except the current one
function! s:HighlightEOLWhitespaceExceptCurrentLine()
call <SID>ClearHighlighting()
if <SID>ShouldHighlight()
let s:match_id = matchadd('ExtraWhitespace',
let w:better_whitespace_match_id = matchadd('ExtraWhitespace',
\ '\%<' . line('.') . 'l' . s:eol_whitespace_pattern .
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern, 10, get(w:, 'better_whitespace_match_id', -1))
endif
endfunction

" Remove Whitespace matching
function! s:ClearHighlighting()
silent! call matchdelete(get(s:, 'match_id', -1))
let match_id = get(w:, 'better_whitespace_match_id', -1)
let valid_ids = map(getmatches(), 'v:val["id"]')
if match_id >= 0 && index(valid_ids, match_id) >= 0
call matchdelete(match_id)
endif
endfunction
endif

Expand Down

0 comments on commit a0a602e

Please sign in to comment.