Post by Jorgen Grahn
I'm used to text files where there's an end of line (LF on Unix) on
every line in a file, even the last one. So that non-empty text files
end with a LF. Editors like Emacs and vi tend to add one, and I got
the impression that not having one is ... not exactly /illegal/, but
Now in the past few years I increasingly see files without that last LF.
They come from coworkers who use various IDEs on Linux.
I notice this when diff reports "no newline at end of file", or
when I edit a file with Emacs and Git reports that I changed the
end of the file.
What's the history of this convention? And is the convention missing
on Windows -- is that why fancy IDEs don't do it?
Certainly don't know about Windows, but here's what Emacs has to say
require-final-newline is a variable defined in ‘files.el’.
Its value is t
Original value was nil
Local in buffer text.txt; global value is nil
This variable is safe as a file local variable if its value
satisfies the predicate ‘symbolp’.
Whether to add a newline automatically at the end of the file.
A value of t means do this only when the file is about to be saved.
A value of ‘visit’ means do this right after the file is visited.
A value of ‘visit-save’ means do it at both of those times.
Any other non-nil value means ask user whether to add a newline, when saving.
A value of nil means don’t add newlines.
Certain major modes set this locally to the value obtained
You can customize this variable.
A quick check shows this value is 't' for .txt and .cpp.
I'm pretty sure Emacs would do the same thing on Windows.
So, I don't think Emacs is generating these files.