If the value of the variable
t, saving or writing a file silently puts a newline at the end
if there isn't already one there. If the value is
adds a newline at the end of any file that doesn't have one, just
after it visits the file. (This marks the buffer as modified, and you
can undo it.) If the value is
visit-save, Emacs adds such
newlines both on visiting and on saving. If the value is
Emacs leaves the end of the file unchanged; any other non-
value means Emacs asks you whether to add a newline. The default is
Some major modes are designed for specific kinds of files that are
always supposed to end in newlines. Such major modes set the variable
require-final-newline to the value of
mode-require-final-newline, which defaults to
setting the latter variable, you can control how these modes handle
Normally, when a program writes a file, the operating system briefly caches the file's data in main memory before committing the data to disk. This can greatly improve performance; for example, when running on laptops, it can avoid a disk spin-up each time a file is written. However, it risks data loss if the operating system crashes before committing the cache to disk.
To lessen this risk, Emacs can invoke the
fsync system call
after saving a file. Using
fsync does not eliminate the risk
of data loss, partly because many systems do not implement
fsync properly, and partly because Emacs's file-saving
procedure typically relies also on directory updates that might not
survive a crash even if
fsync works properly.
write-region-inhibit-fsync variable controls whether
fsync after saving a file. The variable's
default value is
nil when Emacs is interactive, and
when Emacs runs in batch mode (see Batch Mode).
Emacs never uses
fsync when writing auto-save files, as these
files might lose data anyway.