mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-30 05:07:48 +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"
|
(defvar org-babel-matlab-shell-command "matlab -nosplash"
|
||||||
"Shell command to use to run matlab as an external process.")
|
"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)
|
(defun org-babel-execute:matlab (body params)
|
||||||
"Execute a block of matlab code with org-babel."
|
"Execute a block of matlab code with org-babel."
|
||||||
(org-babel-execute:octave body params 'matlab))
|
(org-babel-execute:octave body params 'matlab))
|
||||||
|
|
|
@ -102,7 +102,14 @@ then create. Return the initialized session."
|
||||||
|
|
||||||
(defvar org-babel-octave-wrapper-method
|
(defvar org-babel-octave-wrapper-method
|
||||||
"%s
|
"%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\'")
|
(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
|
(let* ((tmp-file (make-temp-file "org-babel-results-")) exit-code
|
||||||
(stderr
|
(stderr
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert (format (if matlabp org-babel-matlab-wrapper-method org-babel-octave-wrapper-method)
|
(insert (format org-babel-octave-wrapper-method body tmp-file tmp-file))
|
||||||
body tmp-file))
|
|
||||||
(setq exit-code (org-babel-shell-command-on-region
|
(setq exit-code (org-babel-shell-command-on-region
|
||||||
(point-min) (point-max) cmd nil 'replace (current-buffer)))
|
(point-min) (point-max) cmd nil 'replace (current-buffer)))
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
|
@ -149,8 +155,7 @@ value of the last statement in BODY, as elisp."
|
||||||
(value
|
(value
|
||||||
(mapconcat
|
(mapconcat
|
||||||
#'org-babel-chomp
|
#'org-babel-chomp
|
||||||
(list (format (if matlabp org-babel-matlab-wrapper-method org-babel-octave-wrapper-method)
|
(list (format org-babel-octave-wrapper-method body tmp-file tmp-file) org-babel-octave-eoe-indicator) "\n"))))
|
||||||
body tmp-file) org-babel-octave-eoe-indicator) "\n"))))
|
|
||||||
(raw (org-babel-comint-with-output session
|
(raw (org-babel-comint-with-output session
|
||||||
(if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t
|
(if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t
|
||||||
(insert full-body) (comint-send-input nil t))) results)
|
(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.
|
"Import data written to file by octave.
|
||||||
This removes initial blank and comment lines and then calls
|
This removes initial blank and comment lines and then calls
|
||||||
`org-babel-import-elisp-from-file'."
|
`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
|
(with-temp-file temp-file
|
||||||
(insert-file-contents file-name)
|
(insert-file-contents file-name)
|
||||||
(re-search-forward "^[ \t]*[^# \t]" nil t)
|
(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)))
|
(org-babel-import-elisp-from-file temp-file)))
|
||||||
|
|
||||||
(defun org-babel-octave-read-string (string)
|
(defun org-babel-octave-read-string (string)
|
||||||
|
|
Loading…
Reference in a new issue