Next: , Previous: Backup, Up: Saving

18.3.3 Customizing Saving of Files

If the value of the variable require-final-newline is t, saving or writing a file silently puts a newline at the end if there isn't already one there. If the value is visit, Emacs 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 nil, Emacs leaves the end of the file unchanged; any other non-nil value means to asks you whether to add a newline. The default is nil.

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 t. By setting the latter variable, you can control how these modes handle final newlines.

When Emacs saves a file, it invokes the fsync system call to force the data immediately out to disk. This is important for safety if the system crashes or in case of power outage. However, it can be disruptive on laptops using power saving, as it may force a disk spin-up each time you save a file. If you accept an increased risk of data loss, you can set write-region-inhibit-fsync to a non-nil value to disable the synchronization.