Org-mode mailing list
 help / color / mirror / Atom feed
From: No Wayman <iarchivedmywholelife@gmail.com>
To: theophilusx@gmail.com
Cc: emacs-orgmode@gnu.org
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
Message-ID: <87o89184h1.fsf@gmail.com> (raw)
In-Reply-To: <871r5xfa8t.fsf@gmail.com>


> 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	other threads:[~2021-09-10  4:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 22:58 No Wayman
2021-09-10  1:53 ` Tim Cross
2021-09-10  2:38   ` No Wayman [this message]
2021-09-10  6:32 ` Timothy
2021-09-10 15:12   ` No Wayman
2021-09-10 15:15     ` No Wayman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://orgmode.org

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o89184h1.fsf@gmail.com \
    --to=iarchivedmywholelife@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=theophilusx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git