emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make org-mode multi line shell session work sensibly


From: Samuel Loury
Subject: Make org-mode multi line shell session work sensibly
Date: Fri, 08 Jan 2021 09:15:57 +0100

Hi,

I've been trying to work more and more with org-babel recently, and
found out that the session in the shell block does not appear to work
well.

The symptom is the following: When I try to run a code block with noop
lines, like comment, the output gets broken

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC sh :results output :exports both :session 
c66d4791-003d-42af-a4e0-366f5542c604
  echo a
  # noop
  echo b
#+END_SRC

#+RESULTS:
:
: a
: $ b
--8<---------------cut here---------------end--------------->8---

Of course, I would expect
--8<---------------cut here---------------start------------->8---
#+RESULTS:
: a
: b
--8<---------------cut here---------------end--------------->8---

Actually, I went through the code and I think I understand why it has
this behavior, see here for my analysis ->
https://konubinix.eu/braindump/posts/c66d4791-003d-42af-a4e0-366f5542c604/

I tried to patch the code of org-babel-comint-with-output to make it
work correctly, see here ->
https://konubinix.eu/braindump/posts/25b52cc8-71f8-420f-9161-5c60030cede9/

But it feels like it is more of a work around than an elegant solution
to the issue. I am already facing some corner cases and it does not
handle yet the continuation lines, starting with ">".

I was thinking that maybe, in org-babel-sh-evaluate, instead of sending
the lines one by one and interpreting the result, the code could write a
temporary file with the body and source it. Basically all the evaluation
would be

--8<---------------cut here---------------start------------->8---
$ source tmp-file-XXXX
$ echo org-babel-sh-eoe
--8<---------------cut here---------------end--------------->8---

It still would suffer from the no newline behavior I am describing here
-> https://konubinix.eu/braindump/posts/f6206181-09d2-4449-b437-960be2b5dfd2/
But, one step at a time, right?

Then I took though about it. I cannot believe I am the only person
trying to run multi line shell programs with comment in session, am I?

So here are a few questions: Is there anyone with the same use case as I
have? If so, how do you cope with the problem I am facing? If I want to
fix it, what do you think would be the more elegant solution: fixing the
line by line parsing like I was trying to do or sourcing the code to
avoid using line by line parsing?

org-mode is really great, org-babel is awesome and I use it more and
more in my daily life, I hope we will be able to fix this annoying
behavior together.

Thank you for your time,
My best,

PS: the real life use case I am using is the following one: I want to
have a few org-babel snippets to ease my code reviews, as presented in here:
https://konubinix.eu/braindump/posts/564621c3-4a9a-4574-abf8-bd9831b29aa4/

the first snippet has the following output

--8<---------------cut here---------------start------------->8---
: 
: $ $ $ $ $ Ready to make the review of XXX on top of YYY
--8<---------------cut here---------------end--------------->8---

instead of the expected

--8<---------------cut here---------------start------------->8---
: Ready to make the review of XXX on top of YYY
--8<---------------cut here---------------end--------------->8---

And the second one with the header ":results output file", have the
following result

--8<---------------cut here---------------start------------->8---
[[file:
the-directory/diff.diff]]
--8<---------------cut here---------------end--------------->8---

instead of the expected

--8<---------------cut here---------------start------------->8---
[[file:the-directory/diff.diff]]
--8<---------------cut here---------------end--------------->8---

With my workaround, the output is ok.
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]