Skip to content

Commit bf6d1ec

Browse files
committed
Add default blacklist filetypes and ignore 'nofile' buftype
Fix #5 and #30
1 parent 984c8da commit bf6d1ec

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
8585
should stay just as it appears in the line above.
8686
8787
* To disable this plugin for specific file types, add the following to your `~/.vimrc`:
88+
```
89+
let g:better_whitespace_filetypes_blacklist+=['<filetype1>', '<filetype2>', '<etc>']
90+
```
91+
This adds filetypes to the default list of blacklisted filetypes. The
92+
default types that are blacklisted are:
93+
```
94+
['diff', 'gitcommit', 'unite', 'qf', 'help']
95+
```
96+
If you do not want any of these filetypes ignored, simply reset the
97+
blacklist rather than append to it:
8898
```
8999
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>']
90100
```

plugin/better-whitespace.vim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ call s:InitVariable('g:current_line_whitespace_disabled_soft', 0)
3333
call s:InitVariable('g:strip_whitespace_on_save', 0)
3434

3535
" Set this to blacklist specific filetypes
36-
call s:InitVariable('g:better_whitespace_filetypes_blacklist', [])
36+
let default_blacklist=['diff', 'gitcommit', 'unite', 'qf', 'help']
37+
call s:InitVariable('g:better_whitespace_filetypes_blacklist', default_blacklist)
3738

3839
" Only init once
3940
let s:better_whitespace_initialized = 0
@@ -161,6 +162,11 @@ function! s:ToggleStripWhitespaceOnSave()
161162
call <SID>SetupAutoCommands()
162163
endfunction
163164

165+
" Determines if whitespace highlighting should currently be skipped
166+
function! s:ShouldSkipHighlight()
167+
return &buftype == 'nofile' || index(g:better_whitespace_filetypes_blacklist, &ft) >= 0
168+
endfunction
169+
164170
" Run :StripWhitespace to remove end of line whitespace
165171
command! -range=% StripWhitespace call <SID>StripWhitespace( <line1>, <line2> )
166172
" Run :ToggleStripWhitespaceOnSave to enable/disable whitespace stripping on save
@@ -186,7 +192,7 @@ function! <SID>SetupAutoCommands()
186192
augroup better_whitespace
187193
autocmd!
188194

189-
if index(g:better_whitespace_filetypes_blacklist, &ft) >= 0
195+
if <SID>ShouldSkipHighlight()
190196
match ExtraWhitespace ''
191197
return
192198
endif

0 commit comments

Comments
 (0)