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 the first line containing the string Local Variables: and the last line containing the string End:.

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 the first line containing the string
`Local Variables:' and the last line containing the string `End:'."
  (interactive
   (let ((variable (read-file-local-variable "Add file-local variable")))
     ;; Error before reading value.
     (if (equal variable 'lexical-binding)
	 (user-error "The `%s' variable must be set at the start of the file"
		     variable))
     (list variable (read-file-local-variable-value variable) t)))
  (if (equal variable 'lexical-binding)
      (user-error "The `%s' variable must be set at the start of the file"
                  variable))
  (modify-file-local-variable variable value 'add-or-replace interactive))