Skip to content

Commit 166a409

Browse files
Cimbalintpeters
authored andcommitted
Pull all recent updates (#121)
1 parent a05c728 commit 166a409

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,17 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
145145
when you save the file. This can be changed to only the modified lines, by adding
146146
the following to your `~/.vimrc`:
147147
```
148-
let g:strip_only_modified_lines=0
148+
let g:strip_only_modified_lines=1
149149
```
150150
151-
* To disable this plugin for specific file types, add the following to your `~/.vimrc`:
151+
* You can override the binary used to check which lines have been modified in the file.
152+
For example to force a 'diff' installed in a different prefix and ignoring the changes
153+
due to tab expansions, you can set the following:
154+
```
155+
let g:diff_binary='/usr/local/bin/diff -E'
156+
```
157+
158+
* To disable the highlighting for specific file types, add the following to your `~/.vimrc`:
152159
```vim
153160
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>']
154161
```
@@ -157,7 +164,7 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
157164
```vim
158165
['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown']
159166
```
160-
If you do not want any of these filetypes unignored, simply include them in the
167+
If you prefer to also keep these default filetypes ignored, simply include them in the
161168
blacklist:
162169
```vim
163170
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>',

doc/better-whitespace.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ Overrides `g:better_whitespace_enabled`, and can be manually overriden with
6767
`g:strip_only_modified_lines` (defaults to 0)
6868
When stripping whitespace on save, only perform the stripping on the lines
6969
that have been modified.
70-
Uses `diff`, which should be available on all platforms (see |E810|).
70+
Uses an external `diff` command set in `g:diff_binary`, which should be
71+
available on all platforms (see |E810|).
72+
73+
`g:diff_binary`
74+
The binary to use to check which lines have been modified in a file. Defaults
75+
to 'diff' on windows and 'command diff' on unix-like platforms (linux, mac OS,
76+
etc.) to bypass any shell aliases or default options for diff.
7177

7278
`g:strip_max_file_size` (defaults to 1000)
7379
Skip stripping whitespace on files that have more lines than the value in this

plugin/better-whitespace.vim

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ call s:InitVariable('strip_max_file_size', 1000)
6565
" Disable verbosity by default
6666
call s:InitVariable('better_whitespace_verbosity', 0)
6767

68+
" Bypass the aliases set for diff by default
69+
if has("win32") || has("win16")
70+
call s:InitVariable('diff_binary', 'diff.exe')
71+
else
72+
call s:InitVariable('diff_binary', 'command diff')
73+
endif
6874

6975
" Section: Whitespace matching setup
7076

@@ -95,18 +101,18 @@ function! s:WhitespaceInit()
95101
endfunction
96102

97103
" Diff command returning a space-separated list of ranges of new/modified lines (as first,last)
98-
let s:diff_cmd='diff -a --unchanged-group-format="" --old-group-format="" --new-group-format="%dF,%dL " --changed-group-format="%dF,%dL " '
104+
let s:diff_cmd=g:diff_binary.' -a --unchanged-group-format="" --old-group-format="" --new-group-format="%dF,%dL " --changed-group-format="%dF,%dL " '
99105

100106
" Section: Actual work functions
101107

102-
" Function to implement trim() fro vim < 8.0.1630
103-
if v:version > 800 || (v:version == 800 && has('patch-1630'))
108+
" Function to implement trim() if it does not exist
109+
if exists('*trim')
104110
function! s:Trim(s)
105111
return trim(a:s)
106112
endfunction
107113
else
108114
function! s:Trim(s)
109-
return substitute(a:s, '^\s*\(.\{-}\)\s*$', '\1', '')
115+
return substitute(a:s, '^\_s*\(.\{-}\)\_s*$', '\1', '')
110116
endfunction
111117
endif
112118

@@ -155,26 +161,25 @@ if g:current_line_whitespace_disabled_soft == 1
155161
else
156162
" Match Whitespace on all lines
157163
function! s:HighlightEOLWhitespace()
164+
call <SID>ClearHighlighting()
158165
if <SID>ShouldHighlight()
159-
exe 'match ExtraWhitespace "' . s:eol_whitespace_pattern . '"'
160-
else
161-
call <SID>ClearHighlighting()
166+
let s:match_id = matchadd('ExtraWhitespace', s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
162167
endif
163168
endfunction
164169

165170
" Match Whitespace on all lines except the current one
166171
function! s:HighlightEOLWhitespaceExceptCurrentLine()
172+
call <SID>ClearHighlighting()
167173
if <SID>ShouldHighlight()
168-
exe 'match ExtraWhitespace "\%<' . line('.') . 'l' . s:eol_whitespace_pattern .
169-
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern . '"'
170-
else
171-
call <SID>ClearHighlighting()
174+
let s:match_id = matchadd('ExtraWhitespace',
175+
\ '\%<' . line('.') . 'l' . s:eol_whitespace_pattern .
176+
\ '\|\%>' . line('.') . 'l' . s:eol_whitespace_pattern, 10, get(s:, 'match_id', -1))
172177
endif
173178
endfunction
174179

175180
" Remove Whitespace matching
176181
function! s:ClearHighlighting()
177-
match ExtraWhitespace ''
182+
silent! call matchdelete(get(s:, 'match_id', -1))
178183
endfunction
179184
endif
180185

0 commit comments

Comments
 (0)