Skip to content

Commit 88cb517

Browse files
committed
Add an option to pick the diff binary
Ignores aliases set in the shell by default, which closes ntpeters#109
1 parent f5726c4 commit 88cb517

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
148148
let g:strip_only_modified_lines=0
149149
```
150150
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+
151158
* To disable this plugin for specific file types, add the following to your `~/.vimrc`:
152159
```vim
153160
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: 7 additions & 1 deletion
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')
71+
else
72+
call s:InitVariable('diff_binary', 'command diff')
73+
endif
6874

6975
" Section: Whitespace matching setup
7076

@@ -95,7 +101,7 @@ 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

0 commit comments

Comments
 (0)