Function: add-file-local-variable

add-file-local-variable is an autoloaded, interactive and byte-compiled function defined in files-x.el.gz.

Signature

(add-file-local-variable VARIABLE VALUE &optional INTERACTIVE)

Documentation

Add file-local VARIABLE with its VALUE to the Local Variables list.

This command deletes all existing settings of VARIABLE (except mode and eval) and adds a new file-local VARIABLE with VALUE to the Local Variables list.

If there is no Local Variables list in the current file buffer, then this function adds it at the end of the file, with the first line containing the string Local Variables: and the last line containing the string End:.

For adding local variables on the first line of a file, for example for settings like `lexical-binding, which must be specified there, use the add-file-local-variable-prop-line command instead.

If optional variable INTERACTIVE is non-nil, display a message telling the user how to make the new value take effect.

View in manual

Probably introduced at or before Emacs version 23.2.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/files-x.el.gz
;;;###autoload
(defun add-file-local-variable (variable value &optional interactive)
  "Add file-local VARIABLE with its VALUE to the Local Variables list.

This command deletes all existing settings of VARIABLE (except `mode'
and `eval') and adds a new file-local VARIABLE with VALUE to the
Local Variables list.

If there is no Local Variables list in the current file buffer,
then this function adds it at the end of the file, with the first
line containing the string `Local Variables:' and the last line
containing the string `End:'.

For adding local variables on the first line of a file, for example
for settings like `lexical-binding, which must be specified there,
use the `add-file-local-variable-prop-line' command instead.

If optional variable INTERACTIVE is non-nil, display a message telling
the user how to make the new value take effect."
  (interactive
   (let ((variable (read-file-local-variable "Add file-local variable")))
     ;; Error before reading value.
     (if (equal variable 'lexical-binding)
	 (user-error "Use `add-file-local-variable-prop-line' to add the `%s' variable"
		     variable))
     (list variable (read-file-local-variable-value variable) t)))
  (if (equal variable 'lexical-binding)
      (user-error "Use `add-file-local-variable-prop-line' to add the `%s' variable"
                  variable))
  (modify-file-local-variable variable value 'add-or-replace interactive))