1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

The --script option now enforces lexical binding (bug#79760)

* etc/NEWS: Document the change.
* lisp/startup.el (command-line--load-script): Set 'lexical-binding';
if we delete the first line, insert a new line to preserve line
numbers.
(command-line--eval-script): Set 'lexical-binding'.
This commit is contained in:
Pip Cet 2025-11-07 09:12:55 +00:00
parent e2799739a5
commit e5130bdecc
2 changed files with 14 additions and 1 deletions

View file

@ -3168,6 +3168,16 @@ and blocks Emacs, or does not provide ways to limit how often it runs.
* Incompatible Lisp Changes in Emacs 31.1 * Incompatible Lisp Changes in Emacs 31.1
** Files loaded from '-x' and '--script' now use lexical binding.
If you don't have time to adapt your script's code to the lexical
binding dialect (see (info "(elisp)Converting to Lexical Binding")),
you can wrap your code in:
#!/usr/bin/env -S emacs --batch --script
(eval
'(progn
YOUR CODE HERE))
+++ +++
** String mutation has been restricted further. ** String mutation has been restricted further.
'aset' on unibyte strings now requires the new character to be a single 'aset' on unibyte strings now requires the new character to be a single

View file

@ -2961,12 +2961,14 @@ nil default-directory" name)
file file nil t file file nil t
(lambda (buffer file) (lambda (buffer file)
(with-current-buffer buffer (with-current-buffer buffer
(setq-local lexical-binding t)
(goto-char (point-min)) (goto-char (point-min))
;; Removing the #! and then calling `eval-buffer' will make the ;; Removing the #! and then calling `eval-buffer' will make the
;; reader not signal an error if it then turns out that the ;; reader not signal an error if it then turns out that the
;; buffer is empty. ;; buffer is empty.
(when (looking-at "#!") (when (looking-at "#!")
(delete-line)) (delete-line)
(insert ";; -*- lexical-binding: t -*-\n"))
(eval-buffer buffer nil file nil t))))) (eval-buffer buffer nil file nil t)))))
(defun command-line--eval-script (file) (defun command-line--eval-script (file)
@ -2975,6 +2977,7 @@ nil default-directory" name)
(lambda (buffer _) (lambda (buffer _)
(with-current-buffer buffer (with-current-buffer buffer
(goto-char (point-min)) (goto-char (point-min))
(setq-local lexical-binding t)
(when (looking-at "#!") (when (looking-at "#!")
(forward-line)) (forward-line))
(let (value form) (let (value form)