Skip to content
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

diff: fix handling of empty file #510

Closed
wants to merge 1 commit into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Apr 14, 2018

An empty, unchanged file was considered to be changed (a new line
added).
This patch fixes s:write_buffer to use binary mode with writefile to
not append a newline always, and does so manually for non-empty buffers,
according to &endofline, &binary and &fixendofline.

This is taken out of Neomake, and tested there in
https://github.com/neomake/neomake/blob/091d148b/tests/utils.vader#L713-L759.

An empty, unchanged file was considered to be changed (a new line
added).
This patch fixes s:write_buffer to use binary mode with `writefile` to
not append a newline always, and does so manually for non-empty buffers,
according to &endofline, &binary and &fixendofline.

This is taken out of Neomake, and tested there in
https://github.com/neomake/neomake/blob/091d148b/tests/utils.vader#L713-L759.
@airblade
Copy link
Owner

airblade commented Dec 5, 2018

Note to self: vim/vim#3289

airblade added a commit that referenced this pull request Dec 13, 2018
@airblade
Copy link
Owner

Applied in 9a23a2f.

I noticed that a buffer consisting only of a newline had a similar problem so I fixed that in 5c636b1.

@airblade airblade closed this Dec 13, 2018
@airblade
Copy link
Owner

Thanks for your patch :)

@blueyed blueyed deleted the empty-file branch December 13, 2018 17:03
@airblade
Copy link
Owner

@blueyed I think binary mode turns off expandtab (see :h edit-binary) which can cause lines with tabs to show up as modified. Have you encountered this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants