-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unable to save file after recent updates #164
Comments
While investigating further, I've echoed range element (local However, looking on how to avoid the problem, I found that Could you please update your script to that cross-platform method? |
The option you link to would work if you’d like to have a visual diff window open and highlighting of changed lines. (Even if we’re closing the diff afterwards it certainly would cause massive visual disruption.) Also since we want to compare the current (modified) buffer to its corresponding file on disk I’m not sure how we’d open the file without it being a copy of the buffer (i.e. with the same modifications applied). In any case, vim is calling diff to setup these visual diffs, so using diff isn’t the issue itself. The issue is that we’re using options to get exactly the info we want, and that apparently have never been added to the mac version. The fix would be to have a different code path on macOS to determine the modified lines that:
There might be other options on mac’s diff that make this parsing easier (maybe Until the moment someone takes the time to write up an appropriate PR for this, the main workaround remains to install gnu diff on mac, as mentioned in other issues on this topic. It doesn’t have to be in your path and disrupt your workflow, you can dump it in any folder and just point |
Actually @eirnym can you copy here the outputs of |
$ diff --version
Apple diff (based on FreeBSD diff) $ diff --help
usage: diff [-aBbdilpTtw] [-c | -e | -f | -n | -q | -u] [--ignore-case]
[--no-ignore-case] [--normal] [--strip-trailing-cr] [--tabsize]
[-I pattern] [-F pattern] [-L label] file1 file2
diff [-aBbdilpTtw] [-I pattern] [-L label] [--ignore-case]
[--no-ignore-case] [--normal] [--strip-trailing-cr] [--tabsize]
[-F pattern] -C number file1 file2
diff [-aBbdiltw] [-I pattern] [--ignore-case] [--no-ignore-case]
[--normal] [--strip-trailing-cr] [--tabsize] -D string file1 file2
diff [-aBbdilpTtw] [-I pattern] [-L label] [--ignore-case]
[--no-ignore-case] [--normal] [--tabsize] [--strip-trailing-cr]
[-F pattern] -U number file1 file2
diff [-aBbdilNPprsTtw] [-c | -e | -f | -n | -q | -u] [--ignore-case]
[--no-ignore-case] [--normal] [--tabsize] [-I pattern] [-L label]
[-F pattern] [-S name] [-X file] [-x pattern] dir1 dir2
diff [-aBbditwW] [--expand-tabs] [--ignore-all-blanks]
[--ignore-blank-lines] [--ignore-case] [--minimal]
[--no-ignore-file-name-case] [--strip-trailing-cr]
[--suppress-common-lines] [--tabsize] [--text] [--width]
-y | --side-by-side file1 file2
diff [--help] [--version] |
@Cimbali yes, Vim is calling diff underneath, but support multiple versions without any problem. The diff options supplied with the plugin most likely applicable to the gnu diff after some specific version. My guess the diff options won't work on FreeBSD as well. |
I’d say give this a go (not fully tested):
" Diff command returning a space-separated list of ranges of new/modified lines (as first,last)
let s:diff_cmd=g:diff_binary.' -a'
" Get the ranges of changed lines
function! s:ChangedLines()
if !filereadable(expand('%'))
return [[1,line('$')]]
elseif &modified
redir => l:better_whitespace_changes_list
silent! echo system(s:diff_cmd.' '.shellescape(expand('%')).' -', join(getline(1, line('$')), "\n") . "\n")
redir END
let lines=l:better_whitespace_changes_list->split('\n')->filter('match(v:val, "^[0-9,]*[ac][0-9,]*$") > -1')
return lines->map('split(split(v:val, "[ac]")[1], ",")')->map('len(v:val) == 1 ? v:val + v:val : v:val')
endif
return []
endfunction |
I followed NixOS/nix#7286 to install diffutils https://formulae.brew.sh/formula/diffutils Before
After installing diffutils using
Now I am able to strip whitespace on save without any errors. The error message could have been better to show that the diff option is not support. |
Today I've udpated the plugin and since then I'm unable to use plugin in Vim to strip whitespaces on save.
my environment:
When EnableStripWhiteSpaceOnSave is enabled I see following repeating lines:
To narrow down the problem I checked the following:
StripWhitespace
andStripWhitespaceOnChangedLines
StripWhitespace
command works wellStripWhitespaceOnChangedLines
produces following repeating output:The text was updated successfully, but these errors were encountered: