emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Org-babel Matlab (session) output is malformed
Date: Thu, 09 Apr 2020 22:48:11 -0700	[thread overview]
Message-ID: <86eesvopr8.fsf@gmail.com> (raw)

I'm trying to evaluate some Matlab code using org-babel in a session:

#+BEGIN_SRC matlab :session :results output
a = 4;
b = a + 3
c = a - 3
#+END_SRC

And following the org-babel documentation, (something like) this is the output I expect:

#+RESULTS:
#+begin_example
b =

     7

c =

     1
#+end_example

But this is the output I get:

#+RESULTS:
#+begin_example
a = 4;
b = a + 3

b =

     7
c = a - 3

c =

     1
'org_babel_eoe'

ans =

    'org_babel_eoe'
#+end_example

(Including the =#+begin_example= etc)

After going through the source of the function =org-babel= calls, here is what's supposed to happen:

1. =org-babel-octave-evaluate-session= copies the code into the Matlab REPL (calling =matlab-shell= if necessary) and the shell runs it.
2. It then copies the result back as a string up to the end-of-evaluation token, and then removes the original code from the output string.

it looks like =org-babel-octave-evaluate-session= is not reading the end-of-evaluation token (='org_babel_eoe'=) correctly, and not removing the input code from the resulting string either. This looks like it should be an easy fix, but I couldn't figure it out.

Any ideas how to fix this?

Notes:

1. The relevant function(s) are in =/usr/share/emacs/27.0.90/lisp/org/ob-octave.el= or equivalent location. I am using Emacs 27.0.90.

2. The same org-babel module pulls double duty for Octave and Matlab with a flag to distinguish between uses, hence the name. When I run the same test as an Octave source block it runs correctly:
   
#+BEGIN_SRC octave :session :results output
a = 4;
b = a + 3
c = a - 3
#+END_SRC

#+RESULTS:
: 
: b =  7
: c =  1

3. This issue regards evaluation of source blocks with the =:results output= option, where org-babel includes in the results block everything that the REPL prints to stdout. (This is different from the default =:results value= option where only the return value of the block is considered as a result.)


- Karthik


             reply	other threads:[~2020-04-10  7:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10  5:48 Karthik Chikmagalur [this message]
2020-09-04 15:39 ` Org-babel Matlab (session) output is malformed Bastien

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=86eesvopr8.fsf@gmail.com \
    --to=karthikchikmagalur@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).