Skip to content

Commit

Permalink
Prevent errors instead of silencing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed Jun 29, 2022
1 parent c5afbe9 commit 3cf6b78
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugin/better-whitespace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,27 @@ 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(s:, '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(s:, '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)
if match_id >= 0
call matchdelete(match_id)
endif
endfunction
endif

Expand Down

0 comments on commit 3cf6b78

Please sign in to comment.