Variable: mode-require-final-newline

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

Value

t

Documentation

Whether to add a newline at end of file, in certain major modes.

Those modes set require-final-newline to this value when you enable them. They do so because they are often used for files that are supposed to end in newlines, and the question is how to arrange that.

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 do not add newlines. That is a risky choice in this variable since this value is used for modes for files that ought to have final newlines. So if you set this to nil, you must explicitly check and add a final newline, whenever you save a file that really needs one.

This variable was added, or its default value changed, in Emacs 22.1.

View in manual

Probably introduced at or before Emacs version 22.1.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defcustom mode-require-final-newline t
  "Whether to add a newline at end of file, in certain major modes.
Those modes set `require-final-newline' to this value when you enable them.
They do so because they are often used for files that are supposed
to end in newlines, and the question is how to arrange that.

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 do not add newlines.  That is a risky choice in this
variable since this value is used for modes for files that ought to have
final newlines.  So if you set this to nil, you must explicitly check and
add a final newline, whenever you save a file that really needs one."
  :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
  :version "22.1")