From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id GIC0CEqDsGRcWQAASxT56A (envelope-from ) for ; Fri, 14 Jul 2023 01:05:46 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id kNVkCEqDsGTtbQEAauVa8A (envelope-from ) for ; Fri, 14 Jul 2023 01:05:46 +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 D2BB337892 for ; Fri, 14 Jul 2023 01:05:45 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.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=1689289545; a=rsa-sha256; cv=none; b=QNNx/1MhnRUk2mael47IIFosaZNC9GaDspOCurCcUd4NhLaN31wctbg2zvio6yLgOH2LCr oUIfR+Da4Cd46ZuRD14uN+V0gSJ4tWNQdYiavmOQDvqBSc+JYUsJS4XOAJL0HWw/R070bi sZovHYETyxBQkXNTUTfeXuWNimCTNvpsECpI+91HxQSNFRZfMj0Lw3o64WY6VH/IgV1DPB w6SGXLC6S7OwJnMMaZSkX9QgbQWb+LBvQtrzfvZFlyeijEzL/NzEvnlr6lbw/B6MWg9tAD P1jcN9SaJDgMEajJMLgx9DhOcezfTeXXyrd3V/7i3WD3YrrYkeAMXj8d1/v6ZQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.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=1689289545; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=G+tEwP/QPL0nBOHpR7rNvXLqdwwD/kdZ9j/Pb+W80cM=; b=pItdG529B0ZYVSI4BiNN2fMJQ9f4+4bysg9EhBfPbhSN3RgkKossaipuGDDAJJG6e/4OJ8 L0kFLQJB+gsv4QbXyodLhHCPzbsHW26KPaC0Axj6pVRnk3+KHGIQFQnhpDVwf+YBh3XGrC mLrvUdM3pFbKVAdU07+UU6YALjs5jMwv/1NgfnfemnRlLhFG+rmUOcUTKDP9jNjs/5zLrv 5iHSn79qRugghuFNxYcm97mXkz6AOFurTA62RiM1s9lIgXuePqfT8dXa4PkFKoXU/0ZLws TVeci3Pq7WJPKM0Erq0TM9/xR6dE8QcVhY2wkZ3dU0cQW7ZABLaNbWB87il1ug== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qK5Mc-0007IR-HT; Thu, 13 Jul 2023 19:04:46 -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 1qK5Ma-0007IJ-SN for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 19:04:44 -0400 Received: from out-43.mta1.migadu.com ([95.215.58.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK5MY-0001av-RM for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 19:04:44 -0400 References: <874jm7d5ou.fsf@lipklim.org> <87351rd58c.fsf@localhost> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. To: Ihor Radchenko Cc: "emacs-orgmode@gnu.org" Subject: [Pre-PATCH v2] Add the capability to specify lexical scope in tangled files (was: Add new :lexical header argument) Date: Thu, 13 Jul 2023 23:00:13 +0100 In-reply-to: <87351rd58c.fsf@localhost> Message-ID: <87zg3zbegv.fsf@lipklim.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=95.215.58.43; envelope-from=eugene.dev@lipklim.org; helo=out-43.mta1.migadu.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: , Reply-to: Evgenii Klimov From: Evgenii Klimov via "General discussions about Org-mode." Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.13 X-Migadu-Scanner: mx2.migadu.com X-Spam-Score: -5.13 X-Migadu-Queue-Id: D2BB337892 X-TUID: Z4IJZZdABxog --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Evgenii Klimov writes: > >> * lisp/ob-core.el (org-babel-common-header-args-w-values): Add new >> :lexical header argument. > > A short note: ob-emacs-lisp already defines :lexical header arg. See > org-babel-header-args:emacs-lisp. Thanks for pointing it out. Updated the patch to reflect your note and documented the change. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v2-0001-ob-tangle.el-Add-the-capability-to-specify-lexica.patch >From 7e75b55ccb4e82d9341b6b308b558e5d01df5128 Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Thu, 13 Jul 2023 18:16:08 +0100 Subject: [PATCH v2] ob-tangle.el: Add the capability to specify lexical scope in tangled files * lisp/ob-tangle.el (org-babel-tangle): Add the ability to enable lexical binding in Elisp tangled file. * etc/ORG-NEWS (=:lexical= header argument now influences tangled files): Document this change. 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. --- etc/ORG-NEWS | 7 +++++++ lisp/ob-tangle.el | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a4725ae8c..c632c4814 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -284,6 +284,13 @@ setting the ~STYLE~ property for each sub-task. The change is breaking when ~org-use-property-inheritance~ is set to ~t~. ** New and changed options +*** =:lexical= header argument now influences tangled files + +When extracting an Elisp src block, the target's file +~lexical-binding~ variable is set according to the src block's +=:lexical= parameter. If at least one block is set to lexical scope, +then the whole file will be with lexical scope. + *** Commands affected by ~org-fold-catch-invisible-edits~ can now be customized New user option ~org-fold-catch-invisible-edits-commands~ controls diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 1274d0db7..10fe5dcf5 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -262,7 +262,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 +273,8 @@ 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 (org-babel-emacs-lisp-lexical + (funcall get-spec :lexical))) (tangle-mode (funcall get-spec :tangle-mode))) (unless (string-equal block-lang lang) (setq lang block-lang) @@ -294,7 +296,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 --=-=-=--