--- ob-octave.el 2020-11-23 11:22:01.473682045 -0800 +++ ob-octave-new.el 2020-11-23 11:10:07.961900383 -0800 @@ -187,6 +187,7 @@ (org-babel-process-file-name tmp-file 'noquote))) (org-babel-octave-import-elisp-from-file tmp-file)))))) + (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp) "Evaluate BODY in SESSION." @@ -237,12 +238,31 @@ (`output (setq results (if matlabp - (cdr (reverse (delq "" (mapcar #'org-strip-quotes + (cdr (reverse (delete "" (mapcar #'org-strip-quotes (mapcar #'org-trim raw))))) (cdr (member org-babel-octave-eoe-output (reverse (mapcar #'org-strip-quotes (mapcar #'org-trim raw))))))) - (mapconcat #'identity (reverse results) "\n"))))) + ;; This kludge is to remove the input lines from the output. Because of + ;; the special way that MATLAB processes bulk comint output (the output + ;; of each line follows that line) the macro + ;; `org-babel-comint-with-output' cannot remove the echoed commands. The + ;; following handles this manually, by splitting both the original input + ;; (`BODY') and full output (`RESULTS') on newlines, comparing them line + ;; by line and removing all lines in BODY from RESULTS. Note that RESULTS + ;; is already a list of strings so additional care is needed. + (let* ((body-lines (split-string body "\n+")) + (result-lines (flatten-list + (mapcar + (lambda (entry) (reverse (split-string entry "\n"))) + results)))) + (mapconcat + #'identity + (reverse (cl-remove-if + (lambda (line) (member line body-lines)) + result-lines)) "\n") + ))))) + (defun org-babel-octave-import-elisp-from-file (file-name) "Import data from FILE-NAME.