0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 21:37:50 +00:00

babel: matlab: detect end of evaluation under Emacs Link

Currently, this uses the presence of a temporary file to signal that
Matlab Emacs Link evaluation is not yet complete.

Emacs Link support added in collaboration with Christopher Long.
This commit is contained in:
Dan Davison 2010-05-03 21:43:23 -04:00
parent c133dd394e
commit 245d98786d
2 changed files with 20 additions and 3 deletions

View file

@ -55,6 +55,14 @@
evaluation. This will use EmacsLink if (matlab-with-emacs-link)
evaluates to a non-nil value.")
(defvar org-babel-matlab-emacs-link-wrapper-method
"%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
else, save -ascii %s ans
end
delete('%s')
")
(defun org-babel-execute:matlab (body params)
"Execute a block of matlab code with org-babel."
(org-babel-execute:octave body params 'matlab))

View file

@ -155,6 +155,7 @@ value of the last statement in BODY, as elisp."
(defun org-babel-octave-evaluate-session (session body result-type &optional matlabp)
(let* ((tmp-file (make-temp-file "org-babel-results-"))
(wait-file (make-temp-file "org-babel-matlab-emacs-link-wait-signal-"))
(full-body
(case result-type
(output
@ -162,14 +163,22 @@ value of the last statement in BODY, as elisp."
#'org-babel-chomp
(list body org-babel-octave-eoe-indicator) "\n"))
(value
(mapconcat
#'org-babel-chomp
(list (format org-babel-octave-wrapper-method body tmp-file tmp-file) org-babel-octave-eoe-indicator) "\n"))))
(if (and matlabp org-babel-matlab-with-emacs-link)
(concat
(format org-babel-matlab-emacs-link-wrapper-method
body tmp-file tmp-file wait-file) "\n")
(mapconcat
#'org-babel-chomp
(list (format org-babel-octave-wrapper-method body tmp-file tmp-file)
org-babel-octave-eoe-indicator) "\n")))))
(raw (if (and matlabp org-babel-matlab-with-emacs-link)
(save-window-excursion
(with-temp-buffer
(insert full-body)
(write-region "" 'ignored wait-file nil nil nil 'excl)
(matlab-shell-run-region (point-min) (point-max))
(message "Waiting for Matlab Emacs Link")
(while (file-exists-p wait-file) (sit-for 0.01))
"")) ;; matlab-shell-run-region doesn't seem to
;; make *matlab* buffer contents easily
;; available, so :results output currently