I'm trying to evaluate some Matlab code using org-babel in a session:
#+BEGIN_SRC matlab :session :results output
a = 1:10;
b = a + 3
c = a - 3
#+END_SRC
And following the org-babel documentation, this is the output I expect:
b =
4 5 6 7 8 9 10 11 12 13
c =
-2 -1 0 1 2 3 4 5 6 7
But this is the output I get:
#+begin_example
a = 1:10;
b = a + 3
b =
4 5 6 7 8 9 10 11 12 13
c = a - 3
c =
-2 -1 0 1 2 3 4 5 6 7
'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, it looks like here is what's supposed to happen:
org-babel-octave-evaluate-sessioncopies the code into the Matlab REPL (callingmatlab-shellif necessary) and the shell runs it.- 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. 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.
Any ideas how to fix this?
Notes:
- 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.
- This issue regards evaluation of source blocks with the
:results outputoption, where org-babel includes in the results block everything that the REPL prints to stdout. (This is different from the default:results valueoption where only the return value of the block is considered as a result.)