From: Max Nikulin <manikulin@gmail.com>
To: Ken Mankoff <mankoff@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH v4] lisp/ob-screen.el: Support ~:var~ header args for babel blocks
Date: Thu, 16 Mar 2023 22:09:28 +0700 [thread overview]
Message-ID: <276112c4-c9bd-36a0-1e70-36a955b7d3c9@gmail.com> (raw)
In-Reply-To: <87v8j1t2qf.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
On 16/03/2023 17:22, Ihor Radchenko wrote:
> Canceled.
Anyway it does not work.
I have tried to "fix" `org-babel-variable-assignments:screen' by an
extra patch. Perhaps executable name aka :cmd and babel language should
not be rigidly coupled and it may be subject for further improvement.
Ken, you wrote that you have other patches for ob-screen.el. Do you plan
to sent them?
[-- Attachment #2: v4-0001-ob-screen.el-Support-var-for-screen-source-blocks.patch --]
[-- Type: text/x-patch, Size: 2190 bytes --]
From a654876c33a13dafac865fa9ea88176302d810c2 Mon Sep 17 00:00:00 2001
From: "Kenneth D. Mankoff" <mankoff@gmail.com>
Date: Mon, 20 Feb 2023 21:40:39 -0800
Subject: [PATCH v4 1/2] ob-screen.el: Support var for screen source blocks
* lisp/ob-screen.el (org-babel-execute:screen): Parse header params
for `:var', then inject into screen session.
* etc/ORG-NEWS: Document as New Feature
---
etc/ORG-NEWS | 10 ++++++++++
lisp/ob-screen.el | 8 ++++++++
2 files changed, 18 insertions(+)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4ca13af17..3f70dc99a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -131,6 +131,16 @@ selection.
TODO state, priority, tags, statistics cookies, and COMMENT keywords
are allowed in the tree structure.
+*** ob-screen now supports :var header arguments
+
+The ~:var~ header arg is now supported.
+
+#+BEGIN_SRC org
+,#+BEGIN_SRC screen :var x=42
+,echo $x
+,#+END_SRC
+#+END_SRC
+
** Miscellaneous
*** Remove undocumented ~:target~ header parameter in ~ob-clojure~
diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el
index 269538e79..6e6a31ea6 100644
--- a/lisp/ob-screen.el
+++ b/lisp/ob-screen.el
@@ -40,6 +40,10 @@ (org-assert-version)
(require 'ob)
+;; Reuse the variable assignment code from ob-shell
+(defalias 'org-babel-variable-assignments:screen
+ 'org-babel-variable-assignments:shell)
+
(defvar org-babel-screen-location "screen"
"The command location for screen.
In case you want to use a different screen than one selected by your $PATH")
@@ -55,8 +59,12 @@ (defun org-babel-execute:screen (body params)
(message "Sending source code block to interactive terminal session...")
(save-window-excursion
(let* ((session (cdr (assq :session params)))
+ (var-lines (org-babel-variable-assignments:screen params))
(socket (org-babel-screen-session-socketname session)))
(unless socket (org-babel-prep-session:screen session params))
+ (mapcar (lambda (var)
+ (org-babel-screen-session-execute-string session var))
+ var-lines)
(org-babel-screen-session-execute-string
session (org-babel-expand-body:generic body params)))))
--
2.25.1
[-- Attachment #3: v4-0002-ob-screen.el-Do-not-rely-on-org-babel-variable-as.patch --]
[-- Type: text/x-patch, Size: 2128 bytes --]
From 1781c8986346a7ea894269f827cce80bfd5cfa70 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Thu, 16 Mar 2023 21:50:24 +0700
Subject: [PATCH v4 2/2] ob-screen.el: Do not rely on
`org-babel-variable-assignments:shell'
* lisp/ob-screen.el (org-babel-variable-assignments:screen): Use `defun'
instead of `defalias' to call variable assignment function specific
to language obtained from the `:cmd' header argument.
`org-babel-variable-assignments:shell' might be considered as
implementation detail, see
Ihor Radchenko to emacs-orgmode. Re: [PATCH] lisp/ob-screen.el: Support
~:var~ header args for babel blocks. Sun, 26 Feb 2023 12:18:14 +0000.
<https://list.orgmode.org/87lekkzkl5.fsf@localhost>
The implemented approach is not optimal since it does not allow
to decouple interpreter executable (for example python3) and babel
language (for example python).
---
lisp/ob-screen.el | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el
index 6e6a31ea6..5d09fe585 100644
--- a/lisp/ob-screen.el
+++ b/lisp/ob-screen.el
@@ -39,10 +39,23 @@ (require 'org-macs)
(org-assert-version)
(require 'ob)
-
-;; Reuse the variable assignment code from ob-shell
-(defalias 'org-babel-variable-assignments:screen
- 'org-babel-variable-assignments:shell)
+(require 'ob-shell)
+
+(defun org-babel-variable-assignments:screen (params)
+ "Return list of statements to assign block variables.
+
+This is an experimental feature, `:cmd' property from PARAMS
+treated as language while actually it is command (executable) name.
+It works at least for shell interpreters."
+ (and
+ (alist-get :var params)
+ (let* ((cmd (alist-get :cmd params))
+ (lang (and cmd (file-name-base cmd)))
+ (func (and lang (intern
+ (concat "org-babel-variable-assignments:" lang)))))
+ (if (not (fboundp func))
+ (error "Babel language support for %s is not loaded" lang)
+ (funcall func params)))))
(defvar org-babel-screen-location "screen"
"The command location for screen.
--
2.25.1
next prev parent reply other threads:[~2023-03-16 15:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 17:03 [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks Ken Mankoff
2023-02-24 18:33 ` Ken Mankoff
2023-02-25 3:51 ` Max Nikulin
2023-02-25 15:14 ` Ken Mankoff
2023-02-25 15:19 ` Ken Mankoff
2023-02-25 16:05 ` Max Nikulin
2023-02-25 16:47 ` Ken Mankoff
2023-02-26 10:11 ` Max Nikulin
2023-02-27 1:59 ` Ken Mankoff
2023-02-28 10:40 ` Ihor Radchenko
2023-03-16 4:12 ` Ken Mankoff
2023-03-16 10:22 ` Ihor Radchenko
2023-03-16 15:09 ` Max Nikulin [this message]
2023-03-17 11:41 ` [PATCH v4] " Max Nikulin
2023-03-18 12:08 ` Ihor Radchenko
2023-03-19 14:42 ` Ken Mankoff
2023-03-21 14:12 ` Max Nikulin
2023-03-02 13:38 ` [PATCH] " Max Nikulin
2023-02-26 12:18 ` Ihor Radchenko
2023-02-27 1:59 ` Ken Mankoff
2023-02-27 19:43 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=276112c4-c9bd-36a0-1e70-36a955b7d3c9@gmail.com \
--to=manikulin@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mankoff@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
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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.