From: Evgenii Klimov via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: "emacs-orgmode@gnu.org" <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 [thread overview]
Message-ID: <87zg3zbegv.fsf@lipklim.org> (raw)
In-Reply-To: <87351rd58c.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> Evgenii Klimov <eugene.dev@lipklim.org> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-ob-tangle.el-Add-the-capability-to-specify-lexica.patch --]
[-- Type: text/x-diff, Size: 2998 bytes --]
From 7e75b55ccb4e82d9341b6b308b558e5d01df5128 Mon Sep 17 00:00:00 2001
From: Evgenii Klimov <eugene.dev@lipklim.org>
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
next prev parent reply other threads:[~2023-07-13 23:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-13 18:30 [Pre-PATCH] Add new :lexical header argument Evgenii Klimov
2023-07-13 18:41 ` Ihor Radchenko
2023-07-13 22:00 ` Evgenii Klimov via General discussions about Org-mode. [this message]
2023-07-14 9:15 ` [Pre-PATCH v2] Add the capability to specify lexical scope in tangled files (was: Add new :lexical header argument) Ihor Radchenko
2023-07-14 9:23 ` Timothy
2023-07-15 7:45 ` Ihor Radchenko
2023-07-15 16:10 ` Timothy
2023-07-16 9:43 ` Ihor Radchenko
2023-08-23 11:44 ` Ihor Radchenko
2023-08-27 8:20 ` Evgenii Klimov
[not found] <mailman.49.1689350420.11515.emacs-orgmode@gnu.org>
2023-07-14 20:43 ` No Wayman
2023-07-14 21:25 ` Evgenii Klimov
2023-07-14 21:57 ` Thomas S. Dye
2023-07-15 8:12 ` Ihor Radchenko
2023-07-15 16:11 ` Thomas S. Dye
2023-07-15 19:33 ` Berry, Charles
2023-07-16 9:24 ` Ihor Radchenko
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://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zg3zbegv.fsf@lipklim.org \
--to=emacs-orgmode@gnu.org \
--cc=eugene.dev@lipklim.org \
--cc=yantar92@posteo.net \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).