emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks
@ 2023-02-24 17:03 Ken Mankoff
  2023-02-24 18:33 ` Ken Mankoff
  0 siblings, 1 reply; 21+ messages in thread
From: Ken Mankoff @ 2023-02-24 17:03 UTC (permalink / raw)
  To: Org-mode


* ob-screen.el: (org-babel-execute:screen): Parse header params
for `:var', then inject into screen session.
(org-babel-variable-assignments:screen): Copied from
ob-shell.el org-babel-variable-assignments:shell

* etc/ORG-NEWS: Document as New Feature

This change only supports single-value variables
(e.g., ~:var x=42~), not tables or arrays as is
currently supported by some other languages.

---
 etc/ORG-NEWS      | 13 +++++++++++++
 lisp/ob-screen.el | 21 +++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 87ecd77cd..d4b454d13 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -106,6 +106,19 @@ 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 now supports simple single-value variables
+(arrays and tables are not 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..d8f361e50 100644
--- a/lisp/ob-screen.el
+++ b/lisp/ob-screen.el
@@ -55,11 +55,32 @@ 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)))))
 
+(defun org-babel-variable-assignments:screen (params)
+  "Return list of shell statements assigning the block's variables."
+  ;; From ob-shell but change function name from ":shell" to ":screen"
+  (let ((sep (cdr (assq :separator params)))
+       (hline (when (string= "yes" (cdr (assq :hlines params)))
+                (or (cdr (assq :hline-string params))
+                    "hline"))))
+    (mapcar
+     (lambda (pair)
+       (if (string-suffix-p "bash" shell-file-name)
+          (org-babel--variable-assignments:bash
+            (car pair) (cdr pair) sep hline)
+         (org-babel--variable-assignments:sh-generic
+         (car pair) (cdr pair) sep hline)))
+     (org-babel--get-vars params))))
+
+
 (defun org-babel-prep-session:screen (_session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (let* ((session (cdr (assq :session params)))


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-03-21 14:13 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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                     ` [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

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).