From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 0PzeK1JDsGQJLgAASxT56A (envelope-from ) for ; Thu, 13 Jul 2023 20:32:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YO8GLFJDsGSwfAAA9RJhRA (envelope-from ) for ; Thu, 13 Jul 2023 20:32:50 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 748E6589DB for ; Thu, 13 Jul 2023 20:32:49 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=wrLJlj4c; dmarc=pass (policy=quarantine) header.from=lipklim.org; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1689273170; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=h0Mvbscx3IEblksLwcU0IlV55vfpv2BZhqOHFQtvErI=; b=mQROnm1iQMF5PDwrXmHgORlAevxzivOcinEpf5NwZVkK4Gaw4GPceDbOW+4QBRcmfgC5t3 MadIFeFmxRc6/DeHM27vYkCBwlLBa+1AHtimexq7ZFaY4FoUf6vCgOuaKgGZiKreo2lukM 3sbuhmqepua6JgIDaeX8vBbNKXZQFcfC1EQ+R9gNtmct3aY93Xkd3TtpNikDU+LT4ov0tz yIm1C/MnuPl06Db2hhdZ2B9WdFFoo3xeBR1OVLuZOX0OG+MbGbeW9WHxl0AYeZ6wW6y8qb N08oJdFsxA8y9AmgRFUtAT+Ul1TvIzFoJfyoVCQr3qwDrXpm7RZHrgQghDKFYQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=wrLJlj4c; dmarc=pass (policy=quarantine) header.from=lipklim.org; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1689273170; a=rsa-sha256; cv=none; b=PxpL4P6ukFV+isgIcRiEMakLcOVAuiO59DB+ysaGGj7vHmlxPGcqHB2Eh7iLwvPoa2iHpD iv9vh4q1a56oPnTUdTnRNKS1DEhGx0724K64sgL2lcGDFwNVZjAPsB1tNbKlGIPYBtmtqS xCLbLiChghTnq+4A9YB9JnfdEdFwnbGerxJlljVGQ4ZtSqAbprFp3wAMtH9WsQqs+y+tnw KTssMkiHjhXmCht8C8LVuI6DVTDw7JMvoVvT57k8zg3v0ZyOU80elzmL1K9jk7otfHcCj6 rS5LxLBeHIkyRemQXB4cqkjiE361KvRALKod38JR5JJzXdv2/VCP6pqLB99rag== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qK161-0000Of-9W; Thu, 13 Jul 2023 14:31:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK15z-0000Nw-K0 for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 14:31:20 -0400 Received: from out-56.mta0.migadu.com ([2001:41d0:1004:224b::38]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK15x-0007lQ-C6 for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 14:31:19 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lipklim.org; s=key1; t=1689273074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=h0Mvbscx3IEblksLwcU0IlV55vfpv2BZhqOHFQtvErI=; b=wrLJlj4c5mJPdNjwXbnwt1TnrIzDfViZDaSVwNz0X7VDA/1ycjfxbVo5GoslQbqo5syrN0 2M9QR+tOWfaJlGERL8KAgPHvnjSa7Z+DU02SBmAZy10qE9muFR12C2WKmi4T/2UDRfxxrp dPgLdzH3o8zZ2n7aAnbWvgzVQNo0BPg= From: Evgenii Klimov To: "emacs-orgmode@gnu.org" Subject: [Pre-PATCH] Add new :lexical header argument Date: Thu, 13 Jul 2023 19:30:00 +0100 Message-ID: <874jm7d5ou.fsf@lipklim.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2001:41d0:1004:224b::38; envelope-from=eugene.dev@lipklim.org; helo=out-56.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -8.08 X-Migadu-Queue-Id: 748E6589DB X-Migadu-Scanner: mx1.migadu.com X-Migadu-Spam-Score: -8.08 X-TUID: 4SBcaCIOwmLW --=-=-= Content-Type: text/plain Hi, here I propose new header argument to enable scope change (lexical/dynamic binding) of the tangled file. We have :shebang header argument and the new one behaves similarly. If you like the idea I think we should discuss the following: - should we allow to set it for non-elisp blocks? e.g. :shebang is not restricted and `elisp-enable-lexical-binding' is smart enough to use the comment symbol appropriate to the context. - should it be :lexical or :scope. :lexical is long to type, but boolean and clear; scope is shorter, but the user will have to type "dynamic/lexical" or "dyn/lex". - should we add the third option of the argument to explicitly forbid lexical binding? E.g. if we a have source block that rely on the dynamic binding but it could be used in another block with lexical binding via noweb. I'm not sure that it's worth the effort. - which default value to choose? Currently if you tangle it would be dynamic, but lexical binding is the future. After all I'll add tests and update Changelog/Docs if needed. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ob-tangle.el-Add-new-lexical-header-argument.patch >From 3ad56137cb709182dc1bc242cd80a1474078cb95 Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Thu, 13 Jul 2023 18:16:08 +0100 Subject: [PATCH] ob-tangle.el: Add new :lexical header argument * lisp/ob-tangle.el (org-babel-tangle-use-lexical-binding): Add new customization variable. (org-babel-tangle): Add ability to enable lexical binding in tangled file. * lisp/ob-core.el (org-babel-common-header-args-w-values): Add new :lexical header argument. Previously one could achieve this manually, but 1) had to keep in mind to hold this source block top-most, 2) couldn't use comment header argument, as `lexical-binding' variable must be set in the first line of a file. --- lisp/ob-core.el | 1 + lisp/ob-tangle.el | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 47410b53f..c1801a677 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -437,6 +437,7 @@ then run `org-babel-switch-to-session'." (sep . :any) (session . :any) (shebang . :any) + (lexical . ((yes no))) (tangle . ((tangle yes no :any))) (tangle-mode . ((#o755 #o555 #o444 :any))) (var . :any) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 1274d0db7..916dd8489 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -76,6 +76,11 @@ then the name of the language is used." :group 'org-babel-tangle :type 'boolean) +(defcustom org-babel-tangle-use-lexical-binding nil + "Enable lexical binding in tangled file by default." + :group 'org-babel-tangle + :type 'boolean) + (defcustom org-babel-post-tangle-hook nil "Hook run in code files tangled by `org-babel-tangle'." :group 'org-babel-tangle @@ -262,7 +267,7 @@ expression." (when file-name (let ((lspecs (cdr by-fn)) (fnd (file-name-directory file-name)) - modes make-dir she-banged lang) + modes make-dir she-banged scoped lang) ;; drop source-blocks to file ;; We avoid append-to-file as it does not work with tramp. (with-temp-buffer @@ -273,6 +278,9 @@ expression." (get-spec (lambda (name) (cdr (assq name (nth 4 spec))))) (she-bang (let ((sheb (funcall get-spec :shebang))) (when (> (length sheb) 0) sheb))) + (lexicalp (or (string-equal (funcall get-spec :lexical) + "yes") + org-babel-tangle-use-lexical-binding)) (tangle-mode (funcall get-spec :tangle-mode))) (unless (string-equal block-lang lang) (setq lang block-lang) @@ -294,7 +302,10 @@ expression." (when (and she-bang (not she-banged)) (insert (concat she-bang "\n")) (setq she-banged t)) - (org-babel-spec-to-string spec) + (org-babel-spec-to-string spec) + (when (and lexicalp (not scoped)) + (save-excursion (elisp-enable-lexical-binding)) + (setq scoped t)) (setq block-counter (+ 1 block-counter)))) lspecs) (when make-dir -- 2.34.1 --=-=-=--