---- On Sat, 11 Feb 2023 15:56:00 -0500 wrote --- > org-babel-comint-async-filter is capable of taking a similar approach, > and reading/writing to tempfile.
There is some precedence in ob-shell for this. Currently, the cmdline, stdin, and shebang headers use temp files. It may be that implementing async versions of these could use this part of the async API. However, cmdline, stdin, and shebang each use a temporary shell process rather than a dedicated comint, even when the :session header is present. The async implementation requires a comint buffer. > I believe this approach would be > generally more robust, but the major weakness is that it would break if > you SSH'd to a remote host in the middle of the session. Good point. > There was an interesting patch to ob-shell that was never applied, that > took the approach of wrapping the code block in a bash function before > executing; I think it might be a promising approach: > > https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00923.html This is interesting. Thanks for sharing! Instead of writing to a temp file, it could use a here document. Here documents, AFAIK, are POSIX portable, although function definitions aren't. Of course, if we're considering Windows cmd (as we did in a recent bug report), there are all sorts of problems: batch syntax (executed from a file) is different than CLI syntax, functions will implemented using labels (I'm not sure how robust that is), and no here documents. A comint would probably be best for the Windows use-case. ahab@pequod ~$ guix shell dash ahab@pequod ~ [env]$ dash <<- EOF my_function() { echo "hello, world!"; echo "the end"; } my_function; EOF hello, world! the end ahab@pequod ~$ guix shell fish ahab@pequod ~ [env]$ fish <<- EOF > function my_function > echo "hello, world!" > echo "the end" > end > my_function > EOF hello, world! the end > By the way, I took a look at ob-shell for the first time in awhile, and > noticed that ob-shell now forces the prompt to be like: > > org_babel_sh_prompt> > > Which I think makes cleaning up the prompt markers a lot more > robust. But it is a bit ugly, and also seems to break working with shell > sessions started outside of Babel with M-x shell. Is this something you consider a bug?