Skip to content

Commit de99b55

Browse files
authored
Compute changed lines with minimal diff options (#167)
1 parent 86a0579 commit de99b55

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plugin/better-whitespace.vim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function! s:WhitespaceInit()
102102
endfunction
103103

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

107107
" Section: Actual work functions
108108

@@ -266,7 +266,10 @@ function! s:ChangedLines()
266266
redir => l:better_whitespace_changes_list
267267
silent! echo system(s:diff_cmd.' '.shellescape(expand('%')).' -', join(getline(1, line('$')), "\n") . "\n")
268268
redir END
269-
return map(split(s:Trim(l:better_whitespace_changes_list), ' '), 'split(v:val, ",")')
269+
" Get relevant lines (added/changed group headers)
270+
let lines=filter(split(l:better_whitespace_changes_list, '\n'), 'match(v:val, "^[0-9,]*[ac][0-9,]*$") > -1')
271+
" Extract first,last line info (repeat first,first if there’s only first line)
272+
return map(map(lines, 'split(split(v:val, "[ac]")[1], ",")'), 'len(v:val) == 1 ? v:val + v:val : v:val')
270273
endif
271274
return []
272275
endfunction

0 commit comments

Comments
 (0)