Hi Ihor, Please see three attached patches.
001 fixes org-babel-screen-test so that it passes. I went with a short wait in the loop. 002 adds support for non-standard screen location, including spaces in paths. 003 adds support for :var header args. If you approve, I will push these to main once I have write access to the repository. I've also added myself as maintainer for ob-fortran and will push that to the bugfix branch once I am allowed. The last patches were on top of emacs main, not org-mode main, which may be why they did not apply. These are now built off of org-mode main branch. Best, Ken Mankoff
>From 6dfb4f29d66f362ce075d910edc224c8235851b9 Mon Sep 17 00:00:00 2001 From: Ken Mankoff <mank...@gmail.com> Date: Wed, 23 Jul 2025 08:41:57 -0400 Subject: [PATCH 1/3] lisp/ob-screen.el (org-babel-screen-test): Test now passes --- lisp/ob-screen.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el index 554a01406..9efdeac81 100644 --- a/lisp/ob-screen.el +++ b/lisp/ob-screen.el @@ -128,16 +128,15 @@ The terminal should shortly flicker." (body (concat "echo '" random-string "' > " tmpfile "\nexit\n")) tmp-string) (org-babel-execute:screen body org-babel-default-header-args:screen) - ;; XXX: need to find a better way to do the following - (while (not (file-readable-p tmpfile)) - ;; do something, otherwise this will be optimized away - (message "org-babel-screen: File not readable yet.")) + (while (= (nth 7 (file-attributes tmpfile)) 0) ;; file size is 0 + (progn (message "org-babel-screen: Still executing...") + (sleep-for 0.01))) (setq tmp-string (with-temp-buffer (insert-file-contents-literally tmpfile) (buffer-substring (point-min) (point-max)))) (delete-file tmpfile) (message (concat "org-babel-screen: Setup " - (if (string-match random-string tmp-string) + (if (string-match-p random-string tmp-string) "WORKS." "DOESN'T work."))))) -- 2.47.2
>From c65386e3934cb2471397eda8ffea2a33867f68c6 Mon Sep 17 00:00:00 2001 From: Ken Mankoff <mank...@gmail.com> Date: Wed, 23 Jul 2025 08:45:30 -0400 Subject: [PATCH 2/3] lisp/ob-screen.el: Support custom location for 'screen' command * lisp/ob-screen.el: All direct calls to 'screen' now use `org-babel-screen-location`. Also supports custom screen locations including paths with spaces. --- lisp/ob-screen.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el index 9efdeac81..2cdd0b98c 100644 --- a/lisp/ob-screen.el +++ b/lisp/ob-screen.el @@ -67,8 +67,11 @@ In case you want to use a different screen than one selected by your $PATH") (screenrc (cdr (assq :screenrc params))) (process-name (concat "org-babel: terminal (" session ")"))) (apply 'start-process process-name "*Messages*" - terminal `("-T" ,(concat "org-babel: " session) "-e" ,org-babel-screen-location - "-c" ,screenrc "-mS" ,session ,cmd)) + (append (list terminal "-T" (concat "org-babel: " session) "-e") + (list org-babel-screen-location + "-c" screenrc + "-mS" session + cmd))) ;; XXX: Is there a better way than the following? (while (not (org-babel-screen-session-socketname session)) ;; wait until screen session is available before returning @@ -83,13 +86,14 @@ In case you want to use a different screen than one selected by your $PATH") (let ((tmpfile (org-babel-screen-session-write-temp-file session body))) (apply 'start-process (concat "org-babel: screen (" session ")") "*Messages*" org-babel-screen-location - `("-S" ,socket "-X" "eval" "msgwait 0" - ,(concat "readreg z " tmpfile) - "paste z")))))) + (list "-S" socket "-X" "eval" "msgwait 0" + (concat "readreg z " tmpfile) + "paste z")))))) (defun org-babel-screen-session-socketname (session) "Check if SESSION exists by parsing output of \"screen -ls\"." - (let* ((screen-ls (shell-command-to-string "screen -ls")) + (let* ((screen-cmd (format "%S -ls" org-babel-screen-location)) + (screen-ls (shell-command-to-string screen-cmd)) (sockets (delq nil (mapcar -- 2.47.2
>From f2bdb290fc161cfe268d23132f0a73801410cf40 Mon Sep 17 00:00:00 2001 From: Ken Mankoff <mank...@gmail.com> Date: Wed, 23 Jul 2025 08:51:33 -0400 Subject: [PATCH 3/3] lisp/ob-screen.el: Support :var header argument * lisp/ob-screen.el: Support :var header argument similar to org babel shell code blocks. * etc/ORG-NEWS (ob-screen now supports :var header arguments): Document new feature. --- etc/ORG-NEWS | 10 ++++++++++ lisp/ob-screen.el | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4cb7561a8..951c3f290 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -224,6 +224,16 @@ appropriate major mode is unavailable. When editing Dot source blocks, Org now uses Graphviz Dot mode, if installed. +*** 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 + ** New and changed options # Changes dealing with changing default values of customizations, diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el index 2cdd0b98c..8b532df46 100644 --- a/lisp/ob-screen.el +++ b/lisp/ob-screen.el @@ -39,6 +39,7 @@ (org-assert-version) (require 'ob) +(require 'ob-shell) (defvar org-babel-screen-location "screen" "The command location for screen. @@ -54,8 +55,12 @@ In case you want to use a different screen than one selected by your $PATH") \"default\" session is used when none is specified in the PARAMS." (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))))) @@ -123,6 +128,25 @@ In case you want to use a different screen than one selected by your $PATH") (delete-matching-lines "^ +$")) tmpfile)) +(defun org-babel-variable-assignments:screen (params) + "Return variable assignments for a screen source block. +Dispatches to the appropriate shell-specific assignment function +based on the :cmd header argument." + (let* ((cmd (cdr (assq :cmd params))) + (shell (or (and cmd (if (listp cmd) (car cmd) cmd)) "sh")) + (var-helper + (and shell + (intern-soft + (format "org-babel--variable-assignments:%s" shell))))) + (mapcar + (lambda (pair) + (let ((varname (symbol-name (car pair))) + (val (cdr pair))) + (if (and var-helper (fboundp var-helper)) + (funcall var-helper varname val) + (format "%s=%s" varname (org-babel-sh-var-to-sh val))))) + (org-babel--get-vars params)))) + (defun org-babel-screen-test () "Test if the default setup works. The terminal should shortly flicker." -- 2.47.2