فهرست منبع

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.
Dan Davison 15 سال پیش
والد
کامیت
245d98786d
2فایلهای تغییر یافته به همراه20 افزوده شده و 3 حذف شده
  1. 8 0
      contrib/babel/lisp/langs/org-babel-matlab.el
  2. 12 3
      contrib/babel/lisp/langs/org-babel-octave.el

+ 8 - 0
contrib/babel/lisp/langs/org-babel-matlab.el

@@ -55,6 +55,14 @@
   evaluation. This will use EmacsLink if (matlab-with-emacs-link)
   evaluation. This will use EmacsLink if (matlab-with-emacs-link)
   evaluates to a non-nil value.")
   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)
 (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))

+ 12 - 3
contrib/babel/lisp/langs/org-babel-octave.el

@@ -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)
 (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp)
   (let* ((tmp-file (make-temp-file "org-babel-results-"))
   (let* ((tmp-file (make-temp-file "org-babel-results-"))
+	 (wait-file (make-temp-file "org-babel-matlab-emacs-link-wait-signal-"))
 	 (full-body
 	 (full-body
 	  (case result-type
 	  (case result-type
 	    (output
 	    (output
@@ -162,14 +163,22 @@ value of the last statement in BODY, as elisp."
 	      #'org-babel-chomp
 	      #'org-babel-chomp
 	      (list body org-babel-octave-eoe-indicator) "\n"))
 	      (list body org-babel-octave-eoe-indicator) "\n"))
 	    (value
 	    (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)
 	 (raw (if (and matlabp org-babel-matlab-with-emacs-link)
 		  (save-window-excursion
 		  (save-window-excursion
 		    (with-temp-buffer
 		    (with-temp-buffer
 		      (insert full-body)
 		      (insert full-body)
+		      (write-region "" 'ignored wait-file nil nil nil 'excl)
 		      (matlab-shell-run-region (point-min) (point-max))
 		      (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
 		      "")) ;; matlab-shell-run-region doesn't seem to
 			   ;; make *matlab* buffer contents easily
 			   ;; make *matlab* buffer contents easily
 			   ;; available, so :results output currently
 			   ;; available, so :results output currently