emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ken Mankoff <mankoff@gmail.com>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks
Date: Sat, 25 Feb 2023 08:47:46 -0800	[thread overview]
Message-ID: <87sfet7kul.fsf@t480.home> (raw)
In-Reply-To: <d52df549-e144-4c22-029f-318469e062a6@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

Hi Max,

On 2023-02-25 at 08:05 -08, Max Nikulin <manikulin@gmail.com> wrote:
> I believe, it is safer to define
> `org-babel-variable-assignments:screen' some way: alias, substitution,
> function that calls `org-babel-variable-assignments:shell'. I am
> unsure which variant is better. I see a couple of callers for specific
> language in ob-core.el.

How's this with a defalias?

  -k.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-screen.el-Support-var-header-args-for-babel-.patch --]
[-- Type: text/x-diff, Size: 2183 bytes --]

From f7ca0258d72b3da5743b1134718b1d1f0d74491d 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] lisp/ob-screen.el: Support var header args for babel blocks

* 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      | 12 ++++++++++++
 lisp/ob-screen.el |  8 ++++++++
 2 files changed, 20 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 87ecd77cd..0da686354 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -106,6 +106,18 @@ 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
+
+
+
 * Version 9.6
 
 ** Important announcements and breaking changes
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 @@
 
 (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 @@ In case you want to use a different screen than one selected by your $PATH")
   (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.34.1


  reply	other threads:[~2023-02-25 16:48 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 [this message]
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                     ` [PATCH v4] " Max Nikulin
2023-03-17 11:41                       ` 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

  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=87sfet7kul.fsf@t480.home \
    --to=mankoff@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@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 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).