emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Samuel Loury <konubinix@gmail.com>
To: Org-mode <emacs-orgmode@gnu.org>
Subject: Make org-mode multi line shell session work sensibly
Date: Fri, 08 Jan 2021 09:15:57 +0100	[thread overview]
Message-ID: <875z47c08y.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3884 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

             reply	other threads:[~2021-01-08  8:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  8:15 Samuel Loury [this message]
2023-04-02 10:19 ` Make org-mode multi line shell session work sensibly Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875z47c08y.fsf@gmail.com \
    --to=konubinix@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).