Variable: require-final-newline

require-final-newline is a customizable variable defined in files.el.gz.

Documentation

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 from mode-require-final-newline.

This variable is heeded only when visiting files (or saving buffers into files they visit). Writing data to the file system with write-region and the like is not influenced by this variable.

View in manual

Probably introduced at or before Emacs version 21.1.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defcustom require-final-newline nil
  "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
from `mode-require-final-newline'.

This variable is heeded only when visiting files (or saving
buffers into files they visit).  Writing data to the file system
with `write-region' and the like is not influenced by this variable."
  :safe #'symbolp
  :type '(choice (const :tag "When visiting" visit)
		 (const :tag "When saving" t)
		 (const :tag "When visiting or saving" visit-save)
		 (const :tag "Don't add newlines" nil)
		 (other :tag "Ask each time" ask))
  :group 'editing-basics)