mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-30 01:27:53 +00:00
babel: return string results from matlab as strings
Thanks to Bob Jansen
This commit is contained in:
parent
f03c981fc0
commit
e48b8bf577
|
@ -48,10 +48,6 @@
|
|||
(defvar org-babel-matlab-shell-command "matlab -nosplash"
|
||||
"Shell command to use to run matlab as an external process.")
|
||||
|
||||
(defvar org-babel-matlab-wrapper-method
|
||||
"%s
|
||||
save -ascii %s ans")
|
||||
|
||||
(defun org-babel-execute:matlab (body params)
|
||||
"Execute a block of matlab code with org-babel."
|
||||
(org-babel-execute:octave body params 'matlab))
|
||||
|
|
|
@ -102,7 +102,14 @@ then create. Return the initialized session."
|
|||
|
||||
(defvar org-babel-octave-wrapper-method
|
||||
"%s
|
||||
save -text %s ans")
|
||||
if ischar(ans)
|
||||
fid = fopen('%s', 'w')
|
||||
fprintf(fid, ans)
|
||||
fprintf(fid, '\\n')
|
||||
fclose(fid)
|
||||
else
|
||||
save -ascii %s ans
|
||||
end")
|
||||
|
||||
(defvar org-babel-octave-eoe-indicator "\'org_babel_eoe\'")
|
||||
|
||||
|
@ -130,8 +137,7 @@ value of the last statement in BODY, as elisp."
|
|||
(let* ((tmp-file (make-temp-file "org-babel-results-")) exit-code
|
||||
(stderr
|
||||
(with-temp-buffer
|
||||
(insert (format (if matlabp org-babel-matlab-wrapper-method org-babel-octave-wrapper-method)
|
||||
body tmp-file))
|
||||
(insert (format org-babel-octave-wrapper-method body tmp-file tmp-file))
|
||||
(setq exit-code (org-babel-shell-command-on-region
|
||||
(point-min) (point-max) cmd nil 'replace (current-buffer)))
|
||||
(buffer-string))))
|
||||
|
@ -149,8 +155,7 @@ value of the last statement in BODY, as elisp."
|
|||
(value
|
||||
(mapconcat
|
||||
#'org-babel-chomp
|
||||
(list (format (if matlabp org-babel-matlab-wrapper-method org-babel-octave-wrapper-method)
|
||||
body tmp-file) org-babel-octave-eoe-indicator) "\n"))))
|
||||
(list (format org-babel-octave-wrapper-method body tmp-file tmp-file) org-babel-octave-eoe-indicator) "\n"))))
|
||||
(raw (org-babel-comint-with-output session
|
||||
(if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t
|
||||
(insert full-body) (comint-send-input nil t))) results)
|
||||
|
@ -172,11 +177,13 @@ value of the last statement in BODY, as elisp."
|
|||
"Import data written to file by octave.
|
||||
This removes initial blank and comment lines and then calls
|
||||
`org-babel-import-elisp-from-file'."
|
||||
(let ((temp-file (make-temp-file "org-babel-results-")))
|
||||
(let ((temp-file (make-temp-file "org-babel-results-")) beg end)
|
||||
(with-temp-file temp-file
|
||||
(insert-file-contents file-name)
|
||||
(re-search-forward "^[ \t]*[^# \t]" nil t)
|
||||
(delete-region (point-min) (point-at-bol)))
|
||||
(if (< (setq beg (point-min))
|
||||
(setq end (point-at-bol)))
|
||||
(delete-region beg end)))
|
||||
(org-babel-import-elisp-from-file temp-file)))
|
||||
|
||||
(defun org-babel-octave-read-string (string)
|
||||
|
|
Loading…
Reference in a new issue