On 23/07/2025 21:38, Ken Mankoff wrote:

Please see three attached patches.

Thanks. I have re-read the thread and my old notes. I have not tested the patches though, so a part of my questions may be irrelevant.

@@ -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

From some previous variant of the patches:

On 27/02/2023 08:59, Ken Mankoff wrote:
Make did not complain about this, but did suggest mapcar -> mapc.

and in my notes:

make single
ob-screen.el:78:8:Warning: ‘mapcar’ called for effect; use ‘mapc’ or ‘dolist’ instead

I hope, there is no this kind of warnings for the latest patch set.

+(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)))))

My naive expectation is that it should be possible to just do
    (intern-soft (format "org-babel-variable-assignments:%s" shell))
with single dash and
    (funcall var-helper params)

Perhaps a brief comment may mitigate temptation to avoid `mapcar' and to shorten the code.

+    (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))))

Finally an idea for further improvements after these patches will be committed.

On 16/03/2023 11:12, Ken Mankoff wrote:
#+BEGIN_SRC bash
ssh somewhere
python

It would be nice to be able to have something like

#+begin_src screen :cmd ssh somewhere python :var a="test"

An obvious obstacle is complications with determining language for org-babel-variable-assignments:... Perhaps it can be solved by introducing new :lang header argument to explicitly specify language with fallback to current heuristics with :cmd and sh.

#+begin_src screen :cmd ssh somewhere python :lang python :var a="test"

In addition it should allow non-standard executable names
:cmd /home/user/src/bash-9.99/bash-9.99

Ideally wrappers like ssh or screen should be available in a TRAMP-like way for any babel language, but I do not have vision how to properly implement it. With ob-screen it is not really convenient, but should be easy to implement.

Reply via email to