aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2024-11-09 14:02:06 +0200
committerEli Zaretskii2024-11-09 14:02:06 +0200
commitdbcd9d782c94e34baf9aabdaeaa70efb791d8a25 (patch)
tree14e8725d79090cf394f908b94b55c6f88e49f8e6
parent94bf7ad797bb7a3c1faa72d2066a1e9b883c4547 (diff)
downloademacs-dbcd9d782c94e34baf9aabdaeaa70efb791d8a25.tar.gz
emacs-dbcd9d782c94e34baf9aabdaeaa70efb791d8a25.zip
Fix documentation and error message of adding local variables
* 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)
-rw-r--r--lisp/files-x.el22
1 files changed, 15 insertions, 7 deletions
diff --git a/lisp/files-x.el b/lisp/files-x.el
index f70be5f7ff3..5f8c1e9aec2 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -239,18 +239,23 @@ This command deletes all existing settings of VARIABLE (except `mode'
239and `eval') and adds a new file-local VARIABLE with VALUE to the 239and `eval') and adds a new file-local VARIABLE with VALUE to the
240Local Variables list. 240Local Variables list.
241 241
242If there is no Local Variables list in the current file buffer 242If there is no Local Variables list in the current file buffer,
243then this function adds the first line containing the string 243then this function adds it at the end of the file, with the first
244`Local Variables:' and the last line containing the string `End:'." 244line containing the string `Local Variables:' and the last line
245containing the string `End:'.
246
247For adding local variables on the first line of a file, for example
248for settings like `lexical-binding, which must be specified there,
249use the `add-file-local-variable-prop-line' command instead."
245 (interactive 250 (interactive
246 (let ((variable (read-file-local-variable "Add file-local variable"))) 251 (let ((variable (read-file-local-variable "Add file-local variable")))
247 ;; Error before reading value. 252 ;; Error before reading value.
248 (if (equal variable 'lexical-binding) 253 (if (equal variable 'lexical-binding)
249 (user-error "The `%s' variable must be set at the start of the file" 254 (user-error "Use `add-file-local-variable-prop-line' to add the `%s' variable"
250 variable)) 255 variable))
251 (list variable (read-file-local-variable-value variable) t))) 256 (list variable (read-file-local-variable-value variable) t)))
252 (if (equal variable 'lexical-binding) 257 (if (equal variable 'lexical-binding)
253 (user-error "The `%s' variable must be set at the start of the file" 258 (user-error "Use `add-file-local-variable-prop-line' to add the `%s' variable"
254 variable)) 259 variable))
255 (modify-file-local-variable variable value 'add-or-replace interactive)) 260 (modify-file-local-variable variable value 'add-or-replace interactive))
256 261
@@ -394,10 +399,13 @@ from the -*- line ignoring the input argument VALUE."
394 399
395This command deletes all existing settings of VARIABLE (except `mode' 400This command deletes all existing settings of VARIABLE (except `mode'
396and `eval') and adds a new file-local VARIABLE with VALUE to 401and `eval') and adds a new file-local VARIABLE with VALUE to
397the -*- line. 402the -*- line at the beginning of the file.
398 403
399If there is no -*- line at the beginning of the current file buffer 404If there is no -*- line at the beginning of the current file buffer
400then this function adds it." 405then this function adds it.
406
407To add variables to the Local Variables list at the end of the file,
408use the `add-file-local-variable' command instead."
401 (interactive 409 (interactive
402 (let ((variable (read-file-local-variable "Add -*- file-local variable"))) 410 (let ((variable (read-file-local-variable "Add -*- file-local variable")))
403 (list variable (read-file-local-variable-value variable) t))) 411 (list variable (read-file-local-variable-value variable) t)))