emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BUG?][PATCH] Should the `lexical-binding' variable be bound during


From: No Wayman
Subject: Re: [BUG?][PATCH] Should the `lexical-binding' variable be bound during src block with :lexical t? [9.4.6 (9.4.6-ga451f9 @ /home/n/.emacs.d/straight/build/org/)]
Date: Thu, 09 Sep 2021 22:38:06 -0400
User-agent: mu4e 1.5.14; emacs 28.0.50


My thoughts on this would be that if lexical-bindings is supposed to be bound to t, it should be done by eval when it gets a non-nil value for it's optional argument. If I execute (eval FORM t) in an emacs lisp buffer, it looks like lexical-bind is not set either, so I don't think it should be in org either. To set it means we could get the same code behaving differently depending on whether the source block is 'tangled' and then evaluated or evaluated within org, which doesn't feel right.
I agree that we should avoid inconsistency. However it is already present.
You can verify this with the following src block:

#+begin_src emacs-lisp :lexical t :tangle ./dynamic.el :results verbatim
(symbol-value lexical-binding)
#+end_src

1. `org-babel-execute-src-block' with point in the src block => nil (lexical binding enabled) 2. `org-edit-special' with point in the src block, `eval-last-sexp' within *Org Src* buffer => t (lexical binding enabled) 3. Tangle to the block to "dynamic.el", `eval-last-sexp' within "dynamic.el" => nil (dynamic binding)

Might be worth asking on emacs-devel why (eval FORM t) does not set this variable?

I understand why it doesn't. Elisp can be interpreted independent of a buffer, and different buffers need to distinguish which scope to use. It's more a question of what do we gain by leaving it unbound while evaluating a src block? A user can rebind `lexical-binding' without hurting anything. The only case I can think of is if they intend to use it as a free variable, it won't be free. I can't imagine a use case where that would be true while the user is also explicitly requesting lexical binding, though.
IMO, it should be set during evaluation (addressed by my patch).

An alternative solution would be to allow one to set the lexical environment as part of the header args. e.g.

#+begin_src emacs-ilsp :lexical ((lexical-binding . t) t)
(symbol-value lexical-binding)
#+end_src

That way we offer the full flexibility of `eval' to those who would use it.

A separate issue, but one worth considering, is whether or not tangling a `:lexical t` src block should automatically add the file-local variable line in the tangled file.

Prior confusion (its not just me, I swear):

https://emacs.stackexchange.com/questions/61754/how-can-i-enable-lexical-binding-for-elisp-code-in-org-mode#comment100554_61758

https://lists.gnu.org/archive/html/emacs-orgmode/2019-08/msg00247.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]