]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix documentation and error message of adding local variables
authorEli Zaretskii <eliz@gnu.org>
Sat, 9 Nov 2024 12:02:06 +0000 (14:02 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 9 Nov 2024 15:50:24 +0000 (16:50 +0100)
* lisp/files-x.el (add-file-local-variable)
(add-file-local-variable-prop-line): Doc fixes.
(add-file-local-variable): Improve the user-error text.  (Bug#74267)

(cherry picked from commit dbcd9d782c94e34baf9aabdaeaa70efb791d8a25)

lisp/files-x.el

index f70be5f7ff3f386f0b8f7a4b41570ad466e209ff..5f8c1e9aec29c43e63f47735a81edf2093fb49a1 100644 (file)
@@ -239,18 +239,23 @@ 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:'."
+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."
   (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"
+        (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 "The `%s' variable must be set at the start of the file"
+      (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))
 
@@ -394,10 +399,13 @@ from the -*- line ignoring the input argument VALUE."
 
 This command deletes all existing settings of VARIABLE (except `mode'
 and `eval') and adds a new file-local VARIABLE with VALUE to
-the -*- line.
+the -*- line at the beginning of the file.
 
 If there is no -*- line at the beginning of the current file buffer
-then this function adds it."
+then this function adds it.
+
+To add variables to the Local Variables list at the end of the file,
+use the `add-file-local-variable' command instead."
   (interactive
    (let ((variable (read-file-local-variable "Add -*- file-local variable")))
      (list variable (read-file-local-variable-value variable) t)))