[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs script options
From: |
Jens Schmidt |
Subject: |
Re: Emacs script options |
Date: |
Mon, 20 Nov 2023 21:10:35 +0100 |
User-agent: |
Mozilla Thunderbird |
On 2023-11-20 07:10, Sebastian Miele wrote:
> This is the trick that Doom Emacs employs, see
> https://github.com/doomemacs/doomemacs/blob/master/bin/doom.
Aw, I was afraid that somebody might have code-golfed that already.
> But it has a problem with lexical binding. Consider:
>
> #!/bin/sh
> : ; exec emacs --script "$0" -- "$@" #; -*- lexical-binding: t; mode:
> emacs-lisp -*-
>
> (defmacro lexical-binding-p ()
> '(let* ((x t)
> (f (lambda () x))
> (x nil))
> (funcall f)))
>
> (message "%s %s" lexical-binding (lexical-binding-p))
>
> When I run it as a script, the output is "nil nil", i.e., the script
> definitely does not run with lexical binding enabled. When I evaluate
> it in a buffer, the output is "t t".
I tried byte-compiling something similar yesterday, which also
indicated that the byte-compiler compiles with lexical bindings. Only
the scripting machinery sees dynamical bindings.
> When I discovered the problem some while ago, I wanted to report it as
> an issue to Doom Emacs, but the bars for reporting issues to that
> specific project were set to high for me to actually go through the
> process.
>
> But maybe it should be reported as an Emacs bug?
I think chances are good that this gets accepted. It seems that the
scripting machinery expects a semicolon in the very first column,
without that the lexical-binding line is not recognized. Even a
space before the semicolon breaks the recognition.
The problem is in function `lisp_file_lexically_bound_p' from lread.c,
which is indeed much more strict in its recognition of the -*- ... -*-
stanza than the functions `set-auto-mode-1' and
`hack-local-variables-prop-line' from files.el. The Emacs manual
((emacs) Specifying File Variables) only mentions that the stanza
has to be in the first line (or the second one if the first is taken
by a she-bang), without any restriction where the comment has to start.
Would you or Greg report that as a bug?
- Re: Emacs script options, (continued)
- Re: Emacs script options, Sebastian Miele, 2023/11/18
- Re: Emacs script options, Greg Minshall, 2023/11/18
- Re: Emacs script options, Jens Schmidt, 2023/11/19
- Re: Emacs script options, Jens Schmidt, 2023/11/19
- Re: Emacs script options, Greg Minshall, 2023/11/19
- Re: Emacs script options, Jens Schmidt, 2023/11/21
- Re: Emacs script options, Sebastian Miele, 2023/11/22
- Re: Emacs script options, Jens Schmidt, 2023/11/22
- Re: Emacs script options, Greg Minshall, 2023/11/23
- Re: Emacs script options, Sebastian Miele, 2023/11/20
- Re: Emacs script options,
Jens Schmidt <=
- Re: Emacs script options, Sebastian Miele, 2023/11/21