Function: org-babel-octave-evaluate-session

org-babel-octave-evaluate-session is a byte-compiled function defined in ob-octave.el.gz.

Signature

(org-babel-octave-evaluate-session SESSION BODY RESULT-TYPE &optional MATLABP)

Documentation

Evaluate BODY in SESSION.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-octave.el.gz
(defun org-babel-octave-evaluate-session
    (session body result-type &optional matlabp)
  "Evaluate BODY in SESSION."
  (let* ((tmp-file (org-babel-temp-file (if matlabp "matlab-" "octave-")))
	 (wait-file (org-babel-temp-file "matlab-emacs-link-wait-signal-"))
	 (full-body
	  (pcase result-type
	    (`output
	     (mapconcat
	      #'org-babel-chomp
	      (list body org-babel-octave-eoe-indicator) "\n"))
	    (`value
	     (if (and matlabp org-babel-matlab-with-emacs-link)
		 (concat
		  (format org-babel-matlab-emacs-link-wrapper-method
			  body
			  (org-babel-process-file-name tmp-file 'noquote)
			  (org-babel-process-file-name tmp-file 'noquote) wait-file) "\n")
	       (mapconcat
		#'org-babel-chomp
		(list (format org-babel-octave-wrapper-method
			      body
			      (org-babel-process-file-name tmp-file 'noquote)
			      (org-babel-process-file-name tmp-file 'noquote))
		      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
		;; won't work
		(org-babel-comint-with-output
		    (session
		     (if matlabp
			 org-babel-octave-eoe-indicator
		       org-babel-octave-eoe-output)
		     t full-body)
		  (insert full-body) (comint-send-input nil t))))
	 results)
    (pcase result-type
      (`value
       (org-babel-octave-import-elisp-from-file tmp-file))
      (`output
       (setq results
	     (if matlabp
		 (cdr (reverse (delete "" (mapcar #'org-strip-quotes
                                                  (mapcar #'org-trim raw)))))
	       (cdr (member org-babel-octave-eoe-output
			    (reverse (mapcar #'org-strip-quotes
					     (mapcar #'org-trim raw)))))))
       (mapconcat #'identity (reverse results) "\n")))))