Skip to content

Commit 4d45b4a

Browse files
authored
Nvim term fix (#161)
1 parent 1b22dc5 commit 4d45b4a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

plugin/better-whitespace.vim

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,28 @@ else
172172
function! s:HighlightEOLWhitespace()
173173
call <SID>ClearHighlighting()
174174
if <SID>ShouldHighlight()
175-
let s:match_id = matchadd('ExtraWhitespace', s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
175+
let w:better_whitespace_match_id = matchadd('ExtraWhitespace',
176+
\ s:eol_whitespace_pattern, 10, get(w:, 'better_whitespace_match_id', -1))
176177
endif
177178
endfunction
178179

179180
" Match Whitespace on all lines except the current one
180181
function! s:HighlightEOLWhitespaceExceptCurrentLine()
181182
call <SID>ClearHighlighting()
182183
if <SID>ShouldHighlight()
183-
let s:match_id = matchadd('ExtraWhitespace',
184+
let w:better_whitespace_match_id = matchadd('ExtraWhitespace',
184185
\ '\%<' . line('.') . 'l' . s:eol_whitespace_pattern .
185-
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
186+
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern, 10, get(w:, 'better_whitespace_match_id', -1))
186187
endif
187188
endfunction
188189

189190
" Remove Whitespace matching
190191
function! s:ClearHighlighting()
191-
silent! call matchdelete(get(s:, 'match_id', -1))
192+
let match_id = get(w:, 'better_whitespace_match_id', -1)
193+
let valid_ids = map(getmatches(), 'v:val["id"]')
194+
if match_id >= 0 && index(valid_ids, match_id) >= 0
195+
call matchdelete(match_id)
196+
endif
192197
endfunction
193198
endif
194199

@@ -382,6 +387,13 @@ endfunction
382387
autocmd FileType,WinEnter,BufWinEnter * call <SID>SetupAutoCommands()
383388
autocmd ColorScheme * call <SID>WhitespaceInit()
384389

390+
" Also check on specific buftype changes
391+
if has('nvim')
392+
autocmd TermOpen * call <SID>SetupAutoCommands()
393+
else
394+
autocmd TerminalWinOpen * call <SID>SetupAutoCommands()
395+
endif
396+
385397

386398
" Section: Setting of per-buffer higlighting/stripping
387399

0 commit comments

Comments
 (0)