From 3cf6b78e4a457ad301ce8401f0cd218931f18596 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Wed, 29 Jun 2022 15:02:39 +0100 Subject: [PATCH] Prevent errors instead of silencing Fixes #52 --- plugin/better-whitespace.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/better-whitespace.vim b/plugin/better-whitespace.vim index ca88d89..e720596 100644 --- a/plugin/better-whitespace.vim +++ b/plugin/better-whitespace.vim @@ -172,7 +172,8 @@ else function! s:HighlightEOLWhitespace() call ClearHighlighting() if 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 @@ -180,15 +181,18 @@ else function! s:HighlightEOLWhitespaceExceptCurrentLine() call ClearHighlighting() if 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