Browse Source

babel: Allow EmacsLink to be used for matlab session evaluation

To use EmacsLink, the user will need to set
org-babel-matlab-with-emacs-link to a non-nil value, and also arrange
that (matlab-with-emacs-link) evaluates to a non-nil value.
Dan Davison 15 years ago
parent
commit
6f399c20b6

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

@@ -50,6 +50,11 @@
 
 (defun org-babel-expand-body:matlab (body params &optional processed-params) body)
 
+(defvar org-babel-matlab-with-emacs-link nil
+  "If non-nil use matlab-shell-run-region for session
+  evaluation. This will use EmacsLink if (matlab-with-emacs-link)
+  evaluates to a non-nil value.")
+
 (defun org-babel-execute:matlab (body params)
   "Execute a block of matlab code with org-babel."
   (org-babel-execute:octave body params 'matlab))

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

@@ -164,9 +164,18 @@ value of the last statement in BODY, as elisp."
 	     (mapconcat
 	      #'org-babel-chomp
 	      (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)
+	 (raw (if (and matlabp org-babel-matlab-with-emacs-link)
+		  (save-window-excursion
+		    (with-temp-buffer
+		      (insert full-body)
+		      (matlab-shell-run-region (point-min) (point-max))
+		      "")) ;; matlab-shell-run-region doesn't seem to
+			   ;; make *matlab* buffer contents easily
+			   ;; available, so :results output currently
+			   ;; won't work
+		(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)
     (case result-type
       (value
        (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file)))