1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00
org-mode/lisp/ob-octave.el

264 lines
9.6 KiB
EmacsLisp
Raw Normal View History

;;; ob-octave.el --- org-babel functions for octave and matlab evaluation
2010-03-18 18:45:39 +00:00
;; Copyright (C) 2010 Free Software Foundation, Inc.
2010-03-18 18:45:39 +00:00
;; Author: Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
2010-12-10 17:49:40 +00:00
;; Version: 7.4
2010-03-18 18:45:39 +00:00
;; This file is part of GNU Emacs.
2010-03-18 18:45:39 +00:00
;; GNU Emacs is free software: you can redistribute it and/or modify
2010-03-18 18:45:39 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
2010-03-18 18:45:39 +00:00
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
2010-03-18 18:45:39 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2010-03-18 18:45:39 +00:00
;;; Commentary:
;;; Requirements:
;; octave
;; octave-mode.el and octave-inf.el come with GNU emacs
;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))
2010-03-18 18:45:39 +00:00
2010-07-04 15:24:08 +00:00
(declare-function matlab-shell "ext:matlab-mode")
(declare-function matlab-shell-run-region "ext:matlab-mode")
(defvar org-babel-default-header-args:matlab '())
(defvar org-babel-default-header-args:octave '())
(defvar org-babel-matlab-shell-command "matlab -nosplash"
2010-07-13 23:20:08 +00:00
"Shell command to run matlab as an external process.")
2010-03-18 18:45:39 +00:00
(defvar org-babel-octave-shell-command "octave -q"
2010-07-13 23:20:08 +00:00
"Shell command to run octave as an external process.")
2010-03-18 18:45:39 +00:00
(defvar org-babel-matlab-with-emacs-link nil
2010-07-13 23:20:08 +00:00
"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.")
(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')
")
(defvar org-babel-octave-wrapper-method
"%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
else, dlmwrite('%s', ans, '\\t')
end")
(defvar org-babel-octave-eoe-indicator "\'org_babel_eoe\'")
(defvar org-babel-octave-eoe-output "ans = org_babel_eoe")
(defun org-babel-execute:matlab (body params)
2010-07-13 23:20:08 +00:00
"Execute a block of matlab code with Babel."
(org-babel-execute:octave body params 'matlab))
2010-03-18 18:45:39 +00:00
(defun org-babel-execute:octave (body params &optional matlabp)
2010-07-13 23:20:08 +00:00
"Execute a block of octave code with Babel."
babel:removing calls to ob-process-params, and updating use of results * lisp/ob-C.el (org-babel-C-execute): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-R.el (org-babel-execute:R): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-R-variable-assignments): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-asymptote.el (org-babel-execute:asymptote): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-clojure.el (org-babel-execute:clojure): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-dot.el (org-babel-execute:dot): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-emacs-lisp.el (org-babel-expand-body:emacs-lisp): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-execute:emacs-lisp): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-haskell.el (org-babel-execute:haskell): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-js.el (org-babel-execute:js): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-lisp.el (org-babel-execute:lisp): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-ocaml.el (org-babel-execute:ocaml): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-octave.el (org-babel-execute:octave): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-perl.el (org-babel-execute:perl): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-python.el (org-babel-execute:python): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-ruby.el (org-babel-execute:ruby): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-scheme.el (org-babel-execute:scheme): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-screen.el (org-babel-execute:screen): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-prep-session:screen): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-sh.el (org-babel-execute:sh): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-sql.el (org-babel-execute:sql): removing call to org-babel-process-params which should no longer be called from within a language file * ob-haskell.el (org-babel-execute:haskell): Remove reference to processed params * ob-clojure.el (org-babel-execute:clojure): Remove reference to processed params * ob-R.el (org-babel-execute:R): Remove reference to processed params
2010-10-21 11:52:24 +00:00
(let* ((session
(funcall (intern (format "org-babel-%s-initiate-session"
(if matlabp "matlab" "octave")))
babel:removing calls to ob-process-params, and updating use of results * lisp/ob-C.el (org-babel-C-execute): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-R.el (org-babel-execute:R): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-R-variable-assignments): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-asymptote.el (org-babel-execute:asymptote): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-clojure.el (org-babel-execute:clojure): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-dot.el (org-babel-execute:dot): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-emacs-lisp.el (org-babel-expand-body:emacs-lisp): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-execute:emacs-lisp): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-haskell.el (org-babel-execute:haskell): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-js.el (org-babel-execute:js): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-lisp.el (org-babel-execute:lisp): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-ocaml.el (org-babel-execute:ocaml): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-octave.el (org-babel-execute:octave): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-perl.el (org-babel-execute:perl): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-python.el (org-babel-execute:python): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-ruby.el (org-babel-execute:ruby): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-scheme.el (org-babel-execute:scheme): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-screen.el (org-babel-execute:screen): removing call to org-babel-process-params which should no longer be called from within a language file (org-babel-prep-session:screen): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-sh.el (org-babel-execute:sh): removing call to org-babel-process-params which should no longer be called from within a language file * lisp/ob-sql.el (org-babel-execute:sql): removing call to org-babel-process-params which should no longer be called from within a language file * ob-haskell.el (org-babel-execute:haskell): Remove reference to processed params * ob-clojure.el (org-babel-execute:clojure): Remove reference to processed params * ob-R.el (org-babel-execute:R): Remove reference to processed params
2010-10-21 11:52:24 +00:00
(cdr (assoc :session params)) params))
(vars (mapcar #'cdr (org-babel-get-header params :var)))
(result-params (cdr (assoc :result-params params)))
(result-type (cdr (assoc :result-type params)))
2010-03-18 18:45:39 +00:00
(out-file (cdr (assoc :file params)))
(full-body
(org-babel-expand-body:generic
body params (org-babel-variable-assignments:octave params)))
(result (org-babel-octave-evaluate
session full-body result-type matlabp)))
ob: language-specific changes in response to :file arg changes These languages are capable of writing results to file; for several of them this is their only mode of operation. These changes cause the languages to return to ob.el either the computed result, or nil, when they have written results to file themselves. This is in place of the previous method of returning the output file name as a string to ob.el. * lisp/ob-asymptote.el (org-babel-execute:asymptote): Return nil to signal that the intended content has been written to file. * lisp/ob-ditaa.el (org-babel-execute:ditaa): Return nil to signal that the intended content has been written to file. * lisp/ob-dot.el (org-babel-execute:dot): Return nil to signal that the intended content has been written to file. * lisp/ob-gnuplot.el (org-babel-execute:gnuplot): Return nil to signal that the intended content has been written to file. * lisp/ob-latex.el (org-babel-execute:latex): Return nil to signal that the intended content has been written to file. * lisp/ob-mscgen.el (org-babel-execute:mscgen): Return nil to signal that the intended content has been written to file. * lisp/ob-octave.el (org-babel-execute:octave): Return result; not name of output file. * lisp/ob-plantuml.el (org-babel-execute:plantuml): Return nil to signal that the intended content has been written to file. * lisp/ob-python.el (org-babel-execute:python): Return result; not name of output file. * lisp/ob-ruby.el (org-babel-execute:ruby): Return result; not name of output file. * lisp/ob-sass.el (org-babel-execute:sass): Return nil if result has been written to file
2010-12-21 10:21:28 +00:00
(org-babel-reassemble-table
result
(org-babel-pick-name
(cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
(org-babel-pick-name
(cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
2010-03-18 18:45:39 +00:00
(defun org-babel-prep-session:matlab (session params)
"Prepare SESSION according to PARAMS."
(org-babel-prep-session:octave session params 'matlab))
(defun org-babel-variable-assignments:octave (params)
"Return list of octave statements assigning the block's variables"
(mapcar
(lambda (pair)
(format "%s=%s"
(car pair)
(org-babel-octave-var-to-octave (cdr pair))))
removing obsoleted optional third argument from org-babel-expand-body:LANG * lisp/ob-C.el (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-expand-body:c++): removing obsoleted optional third argument (org-babel-C-expand): removing obsoleted optional third argument * lisp/ob-R.el: (org-babel-expand-body:R): removing obsoleted optional third argument (org-babel-execute:R): removing obsoleted optional third argument (org-babel-R-variable-assignments): removing obsoleted optional third argument * lisp/ob-asymptote.el: (org-babel-expand-body:asymptote): removing obsoleted optional third argument (org-babel-execute:asymptote): removing obsoleted optional third argument * lisp/ob-clojure.el: (org-babel-expand-body:clojure): removing obsoleted optional third argument (org-babel-execute:clojure): removing obsoleted optional third argument * lisp/ob-css.el: (org-babel-expand-body:css): removing obsoleted optional third argument * lisp/ob-ditaa.el: (org-babel-expand-body:ditaa): removing obsoleted optional third argument * lisp/ob-dot.el: (org-babel-expand-body:dot): removing obsoleted optional third argument (org-babel-execute:dot): removing obsoleted optional third argument * lisp/ob-emacs-lisp.el: (org-babel-expand-body:emacs-lisp): removing obsoleted optional third argument (org-babel-execute:emacs-lisp): removing obsoleted optional third argument * lisp/ob-gnuplot.el: (org-babel-expand-body:gnuplot): removing obsoleted optional third argument * lisp/ob-haskell.el: (org-babel-expand-body:haskell): removing obsoleted optional third argument (org-babel-execute:haskell): removing obsoleted optional third argument (org-babel-load-session:haskell): removing obsoleted optional third (org-babel-prep-session:haskell): removing obsoleted optional third * lisp/ob-js.el: (org-babel-expand-body:js): removing obsoleted optional third argument (org-babel-execute:js): removing obsoleted optional third argument * lisp/ob-latex.el: (org-babel-expand-body:latex): removing obsoleted optional third argument * lisp/ob-lisp.el: (org-babel-expand-body:lisp): removing obsoleted optional third argument (org-babel-execute:lisp): removing obsoleted optional third argument * lisp/ob-mscgen.el: (org-babel-expand-body:mscgen): removing obsoleted optional third argument * lisp/ob-ocaml.el: (org-babel-expand-body:ocaml): removing obsoleted optional third argument (org-babel-execute:ocaml): removing obsoleted optional third argument * lisp/ob-octave.el: (org-babel-expand-body:matlab): removing obsoleted optional third argument (org-babel-expand-body:octave): removing obsoleted optional third argument (org-babel-execute:octave): removing obsoleted optional third argument (org-babel-octave-variable-assignments): removing obsoleted optional third * lisp/ob-org.el: (org-babel-expand-body:org): removing obsoleted optional third argument * lisp/ob-perl.el: (org-babel-expand-body:perl): removing obsoleted optional third argument (org-babel-execute:perl): removing obsoleted optional third argument * lisp/ob-plantuml.el: (org-babel-expand-body:plantuml): removing obsoleted optional third argument * lisp/ob-python.el: (org-babel-expand-body:python): removing obsoleted optional third argument (org-babel-execute:python): removing obsoleted optional third argument (org-babel-python-variable-assignments): removing obsoleted optional third * lisp/ob-ruby.el: (org-babel-expand-body:ruby): removing obsoleted optional third argument (org-babel-execute:ruby): removing obsoleted optional third argument * lisp/ob-sass.el: (org-babel-expand-body:sass): removing obsoleted optional third argument * lisp/ob-scheme.el: (org-babel-expand-body:scheme): removing obsoleted optional third argument (org-babel-execute:scheme): removing obsoleted optional third argument * lisp/ob-screen.el: (org-babel-expand-body:screen): removing obsoleted optional third argument * lisp/ob-sh.el: (org-babel-expand-body:sh): removing obsoleted optional third argument (org-babel-execute:sh): removing obsoleted optional third argument (org-babel-sh-variable-assignments): removing obsoleted optional third * lisp/ob-sql.el: (org-babel-expand-body:sql): removing obsoleted optional third argument * lisp/ob-sqlite.el: (org-babel-expand-body:sqlite): removing obsoleted optional third argument (org-babel-execute:sqlite): removing obsoleted optional third argument * lisp/ob.el: (org-babel-expand-body:generic): removing obsoleted optional third argument
2010-10-16 03:35:45 +00:00
(mapcar #'cdr (org-babel-get-header params :var))))
(defalias 'org-babel-variable-assignments:matlab
'org-babel-variable-assignments:octave)
2010-03-18 18:45:39 +00:00
(defun org-babel-octave-var-to-octave (var)
2010-07-13 23:20:08 +00:00
"Convert an emacs-lisp value into an octave variable.
2010-03-18 18:45:39 +00:00
Converts an emacs-lisp variable into a string of octave code
specifying a variable of the same value."
(if (listp var)
From: Juan <Pechiar@computer.org> Hi, I'm starting to work with ob-octave and found several problems: The first, for which I have a fix (see patch below) is that octave's output was passed on as a string instead of being interpreted as a table: [diff removed] Now this works: 8<------------------------------------------------------------ #+source: test_output #+begin_src octave :results value vector [[1 2 3];[4 5 6]] #+end_src #+results: test_output | 1.00000000e+00 | 2.00000000e+00 | 3.00000000e+00 | | 4.00000000e+00 | 5.00000000e+00 | 6.00000000e+00 | 8<------------------------------------------------------------ (before the patch you'd get a single table element with something like "1 2 3\n 4 5 6\n" inside). The second problem is that if I use octave table output as input to another block, it gets interpreted as a string instead of a vector: 8<------------------------------------------------------------ #+results: test_output | 1.25000000e+00 | #+source: check_input #+begin_src octave :var input=test_output() :results output ischar( input ) size( input ) #+end_src #+results: check_input : input = 1.25000000e+00 : ans = 1 : ans = : 1 14 8<------------------------------------------------------------ This has to do with the EXP notation. The 'e+00' suffix makes the whole table into a string. The problem is with "%S" in the formatting inside org-babel-octave-var-to-octave. The following patch seems to fix it (and makes it possible to work with complex numbers inside the tables):: [diff removed] A third problem is with org-babel-octave-var-to-octave. For example: : (org-babel-octave-var-to-octave '( ( 1 2 3 ) ( 4 5 6 ) )) : -> "[[1, 2, 3], [4, 5, 6]]" This is not a 2x3 matrix, but a 1x6 vector: : octave-3.2.3:1> [[1,2,3],[4,5,6]] : ans = : 1 2 3 4 5 6 a semicolon ';' or '\n' is needed between rows instead of a comma. To sum up: - 2 patches for prepare-session and importing the results back as org-tables (I don't know if these patches break anything). - 1 problem with matrix notation in org-babel-octave-var-to-octave. I'll try to provide a patch for this today. 2010-08-01 Juan Pechiar <Pechiar@computer.org> * ob-octave.el (org-babel-octave-evaluate-external-process): use `org-babel-octave-import-elisp-from-file' instead of `org-babel-eval-read-file'. (org-babel-octave-var-to-octave): separate matrix rows with ';', and use '%s' as format specifier instead of '%S'
2010-08-01 22:09:24 +00:00
(concat "[" (mapconcat #'org-babel-octave-var-to-octave var
(if (listp (car var)) "; " ",")) "]")
(format "%s" (or var "nil"))))
2010-03-18 18:45:39 +00:00
(defun org-babel-prep-session:octave (session params &optional matlabp)
"Prepare SESSION according to the header arguments specified in PARAMS."
(let* ((session (org-babel-octave-initiate-session session params matlabp))
(var-lines (org-babel-variable-assignments:octave params)))
2010-03-18 18:45:39 +00:00
(org-babel-comint-in-buffer session
(mapc (lambda (var)
(end-of-line 1) (insert var) (comint-send-input nil t)
2010-03-18 18:45:39 +00:00
(org-babel-comint-wait-for-output session)) var-lines))
session))
(defun org-babel-matlab-initiate-session (&optional session params)
2010-07-13 23:20:08 +00:00
"Create a matlab inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
(org-babel-octave-initiate-session session params 'matlab))
2010-03-18 18:45:39 +00:00
(defun org-babel-octave-initiate-session (&optional session params matlabp)
2010-07-13 23:20:08 +00:00
"Create an octave inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
(if matlabp (require 'matlab) (require 'octave-inf))
2010-03-18 18:45:39 +00:00
(unless (string= session "none")
(let ((session (or session
(if matlabp "*Inferior Matlab*" "*Inferior Octave*"))))
2010-03-18 18:45:39 +00:00
(if (org-babel-comint-buffer-livep session) session
(save-window-excursion
(if matlabp (unless org-babel-matlab-with-emacs-link (matlab-shell))
(run-octave))
2010-03-18 18:45:39 +00:00
(rename-buffer (if (bufferp session) (buffer-name session)
(if (stringp session) session (buffer-name))))
(current-buffer))))))
2010-03-18 18:45:39 +00:00
(defun org-babel-octave-evaluate
(session body result-type &optional matlabp)
2010-07-13 23:20:08 +00:00
"Pass BODY to the octave process in SESSION.
If RESULT-TYPE equals 'output then return the outputs of the
statements in BODY, if RESULT-TYPE equals 'value then return the
value of the last statement in BODY, as elisp."
2010-03-18 18:45:39 +00:00
(if session
(org-babel-octave-evaluate-session session body result-type matlabp)
2010-03-18 18:45:39 +00:00
(org-babel-octave-evaluate-external-process body result-type matlabp)))
(defun org-babel-octave-evaluate-external-process (body result-type matlabp)
"Evaluate BODY in an external octave process."
(let ((cmd (if matlabp
org-babel-matlab-shell-command
org-babel-octave-shell-command)))
(case result-type
(output (org-babel-eval cmd body))
(value (let ((tmp-file (org-babel-temp-file "octave-")))
(org-babel-eval
cmd
babel: New function to process file names for use in external processes * ob.el (org-babel-process-file-name): New function (org-babel-maybe-remote-file): Delete function * ob-sql.el (org-babel-execute:sql): Use org-babel-process-file-name * ob-scheme.el (org-babel-execute:scheme): Use org-babel-process-file-name * ob-sass.el (org-babel-execute:sass): Use org-babel-process-file-name * ob-ruby.el (org-babel-ruby-evaluate): Use org-babel-process-file-name * ob-python.el (org-babel-python-evaluate-external-process): Use org-babel-process-file-name (org-babel-python-evaluate-session): Use org-babel-process-file-name * ob-plantuml.el (org-babel-execute:plantuml): Use org-babel-process-file-name * ob-perl.el (org-babel-perl-evaluate): Use org-babel-process-file-name * ob-octave.el (org-babel-octave-evaluate-external-process): Use org-babel-process-file-name (org-babel-octave-evaluate-session): Use org-babel-process-file-name, don't use org-babel-maybe-remote-file * ob-lisp.el (org-babel-execute:lisp): Use org-babel-process-file-name * ob-ledger.el (org-babel-execute:ledger): Use org-babel-process-file-name * ob-js.el (org-babel-execute:js): Use org-babel-process-file-name * ob-haskell.el (org-babel-haskell-export-to-lhs): Use org-babel-process-file-name * ob-gnuplot.el (org-babel-execute:gnuplot): Use org-babel-process-file-name * ob-eval.el (org-babel-eval-read-file): Don't use org-babel-maybe-remote-file * ob-dot.el (org-babel-execute:dot): Use org-babel-process-file-name * ob-ditaa.el (org-babel-execute:ditaa): Use org-babel-process-file-name * ob-clojure.el (org-babel-clojure-evaluate-external-process): Use org-babel-process-file-name * ob-asymptote.el (org-babel-execute:asymptote): Use org-babel-process-file-name * ob-R.el (org-babel-R-assign-elisp): Don't use org-babel-maybe-remote-file, use org-babel-process-file-name (org-babel-R-evaluate-external-process): Use org-babel-process-file-name (org-babel-R-evaluate-session): Use org-babel-process-file-name * ob-C.el (org-babel-C-execute): Use org-babel-process-file-name In addition to passing the file path through `expand-file-name', tramp-style remote file names are converted to conventional (local) file paths. The reason is that, if a tramp file name was in use in emacs, then the shell command will be executing on the remote machine in question. Further, by default the file name is passed through `shell-quote-argument'.
2010-09-22 20:40:14 +00:00
(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-import-elisp-from-file tmp-file))))))
(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-")))
Babel now cleans up any temporary files created using org-babel-temp-file * lisp/ob.el (org-babel-temporary-directory): variable to hold the value of the Babel temporary directory (org-babel-temp-file): replacement for make-temp-file with cleanup on exit of Emacs (org-babel-remove-temporary-directory): cleanup function run on exit of Emacs (kill-emacs-hook): now includes babel cleanup function * lisp/ob-C.el (org-babel-C-execute): using org-babel-temp-file instead of make-temp-file * lisp/ob-R.el (org-babel-R-assign-elisp): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-asymptote.el (org-babel-execute:asymptote): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-clojure.el (org-babel-clojure-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ditaa.el (org-babel-execute:ditaa): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-dot.el (org-babel-execute:dot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-execute:gnuplot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-haskell.el (org-babel-load-session:haskell): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-haskell-export-to-lhs): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-latex.el (org-babel-execute:latex): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ledger.el (org-babel-execute:ledger): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-lisp.el (org-babel-execute:lisp): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-import-elisp-from-file): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-perl.el (org-babel-perl-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-python.el (org-babel-python-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ruby.el (org-babel-ruby-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sass.el (org-babel-execute:sass): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sh.el (org-babel-sh-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sql.el (org-babel-execute:sql): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sqlite.el (org-babel-execute:sqlite): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-sqlite-expand-vars): using `org-babel-temp-file' instead of `make-temp-file'
2010-08-25 20:43:07 +00:00
(wait-file (org-babel-temp-file "matlab-emacs-link-wait-signal-"))
2010-03-18 18:45:39 +00:00
(full-body
(case 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
babel: New function to process file names for use in external processes * ob.el (org-babel-process-file-name): New function (org-babel-maybe-remote-file): Delete function * ob-sql.el (org-babel-execute:sql): Use org-babel-process-file-name * ob-scheme.el (org-babel-execute:scheme): Use org-babel-process-file-name * ob-sass.el (org-babel-execute:sass): Use org-babel-process-file-name * ob-ruby.el (org-babel-ruby-evaluate): Use org-babel-process-file-name * ob-python.el (org-babel-python-evaluate-external-process): Use org-babel-process-file-name (org-babel-python-evaluate-session): Use org-babel-process-file-name * ob-plantuml.el (org-babel-execute:plantuml): Use org-babel-process-file-name * ob-perl.el (org-babel-perl-evaluate): Use org-babel-process-file-name * ob-octave.el (org-babel-octave-evaluate-external-process): Use org-babel-process-file-name (org-babel-octave-evaluate-session): Use org-babel-process-file-name, don't use org-babel-maybe-remote-file * ob-lisp.el (org-babel-execute:lisp): Use org-babel-process-file-name * ob-ledger.el (org-babel-execute:ledger): Use org-babel-process-file-name * ob-js.el (org-babel-execute:js): Use org-babel-process-file-name * ob-haskell.el (org-babel-haskell-export-to-lhs): Use org-babel-process-file-name * ob-gnuplot.el (org-babel-execute:gnuplot): Use org-babel-process-file-name * ob-eval.el (org-babel-eval-read-file): Don't use org-babel-maybe-remote-file * ob-dot.el (org-babel-execute:dot): Use org-babel-process-file-name * ob-ditaa.el (org-babel-execute:ditaa): Use org-babel-process-file-name * ob-clojure.el (org-babel-clojure-evaluate-external-process): Use org-babel-process-file-name * ob-asymptote.el (org-babel-execute:asymptote): Use org-babel-process-file-name * ob-R.el (org-babel-R-assign-elisp): Don't use org-babel-maybe-remote-file, use org-babel-process-file-name (org-babel-R-evaluate-external-process): Use org-babel-process-file-name (org-babel-R-evaluate-session): Use org-babel-process-file-name * ob-C.el (org-babel-C-execute): Use org-babel-process-file-name In addition to passing the file path through `expand-file-name', tramp-style remote file names are converted to conventional (local) file paths. The reason is that, if a tramp file name was in use in emacs, then the shell command will be executing on the remote machine in question. Further, by default the file name is passed through `shell-quote-argument'.
2010-09-22 20:40:14 +00:00
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
babel: New function to process file names for use in external processes * ob.el (org-babel-process-file-name): New function (org-babel-maybe-remote-file): Delete function * ob-sql.el (org-babel-execute:sql): Use org-babel-process-file-name * ob-scheme.el (org-babel-execute:scheme): Use org-babel-process-file-name * ob-sass.el (org-babel-execute:sass): Use org-babel-process-file-name * ob-ruby.el (org-babel-ruby-evaluate): Use org-babel-process-file-name * ob-python.el (org-babel-python-evaluate-external-process): Use org-babel-process-file-name (org-babel-python-evaluate-session): Use org-babel-process-file-name * ob-plantuml.el (org-babel-execute:plantuml): Use org-babel-process-file-name * ob-perl.el (org-babel-perl-evaluate): Use org-babel-process-file-name * ob-octave.el (org-babel-octave-evaluate-external-process): Use org-babel-process-file-name (org-babel-octave-evaluate-session): Use org-babel-process-file-name, don't use org-babel-maybe-remote-file * ob-lisp.el (org-babel-execute:lisp): Use org-babel-process-file-name * ob-ledger.el (org-babel-execute:ledger): Use org-babel-process-file-name * ob-js.el (org-babel-execute:js): Use org-babel-process-file-name * ob-haskell.el (org-babel-haskell-export-to-lhs): Use org-babel-process-file-name * ob-gnuplot.el (org-babel-execute:gnuplot): Use org-babel-process-file-name * ob-eval.el (org-babel-eval-read-file): Don't use org-babel-maybe-remote-file * ob-dot.el (org-babel-execute:dot): Use org-babel-process-file-name * ob-ditaa.el (org-babel-execute:ditaa): Use org-babel-process-file-name * ob-clojure.el (org-babel-clojure-evaluate-external-process): Use org-babel-process-file-name * ob-asymptote.el (org-babel-execute:asymptote): Use org-babel-process-file-name * ob-R.el (org-babel-R-assign-elisp): Don't use org-babel-maybe-remote-file, use org-babel-process-file-name (org-babel-R-evaluate-external-process): Use org-babel-process-file-name (org-babel-R-evaluate-session): Use org-babel-process-file-name * ob-C.el (org-babel-C-execute): Use org-babel-process-file-name In addition to passing the file path through `expand-file-name', tramp-style remote file names are converted to conventional (local) file paths. The reason is that, if a tramp file name was in use in emacs, then the shell command will be executing on the remote machine in question. Further, by default the file name is passed through `shell-quote-argument'.
2010-09-22 20:40:14 +00:00
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)
2010-03-18 18:45:39 +00:00
(case result-type
(value
babel: New function to process file names for use in external processes * ob.el (org-babel-process-file-name): New function (org-babel-maybe-remote-file): Delete function * ob-sql.el (org-babel-execute:sql): Use org-babel-process-file-name * ob-scheme.el (org-babel-execute:scheme): Use org-babel-process-file-name * ob-sass.el (org-babel-execute:sass): Use org-babel-process-file-name * ob-ruby.el (org-babel-ruby-evaluate): Use org-babel-process-file-name * ob-python.el (org-babel-python-evaluate-external-process): Use org-babel-process-file-name (org-babel-python-evaluate-session): Use org-babel-process-file-name * ob-plantuml.el (org-babel-execute:plantuml): Use org-babel-process-file-name * ob-perl.el (org-babel-perl-evaluate): Use org-babel-process-file-name * ob-octave.el (org-babel-octave-evaluate-external-process): Use org-babel-process-file-name (org-babel-octave-evaluate-session): Use org-babel-process-file-name, don't use org-babel-maybe-remote-file * ob-lisp.el (org-babel-execute:lisp): Use org-babel-process-file-name * ob-ledger.el (org-babel-execute:ledger): Use org-babel-process-file-name * ob-js.el (org-babel-execute:js): Use org-babel-process-file-name * ob-haskell.el (org-babel-haskell-export-to-lhs): Use org-babel-process-file-name * ob-gnuplot.el (org-babel-execute:gnuplot): Use org-babel-process-file-name * ob-eval.el (org-babel-eval-read-file): Don't use org-babel-maybe-remote-file * ob-dot.el (org-babel-execute:dot): Use org-babel-process-file-name * ob-ditaa.el (org-babel-execute:ditaa): Use org-babel-process-file-name * ob-clojure.el (org-babel-clojure-evaluate-external-process): Use org-babel-process-file-name * ob-asymptote.el (org-babel-execute:asymptote): Use org-babel-process-file-name * ob-R.el (org-babel-R-assign-elisp): Don't use org-babel-maybe-remote-file, use org-babel-process-file-name (org-babel-R-evaluate-external-process): Use org-babel-process-file-name (org-babel-R-evaluate-session): Use org-babel-process-file-name * ob-C.el (org-babel-C-execute): Use org-babel-process-file-name In addition to passing the file path through `expand-file-name', tramp-style remote file names are converted to conventional (local) file paths. The reason is that, if a tramp file name was in use in emacs, then the shell command will be executing on the remote machine in question. Further, by default the file name is passed through `shell-quote-argument'.
2010-09-22 20:40:14 +00:00
(org-babel-octave-import-elisp-from-file tmp-file))
2010-03-18 18:45:39 +00:00
(output
(progn
(setq results
(if matlabp
(cdr (reverse (delq "" (mapcar
#'org-babel-octave-read-string
(mapcar #'org-babel-trim raw)))))
2010-03-18 18:45:39 +00:00
(cdr (member org-babel-octave-eoe-output
(reverse (mapcar
#'org-babel-octave-read-string
(mapcar #'org-babel-trim raw)))))))
2010-03-18 18:45:39 +00:00
(mapconcat #'identity (reverse results) "\n"))))))
(defun org-babel-octave-import-elisp-from-file (file-name)
2010-07-13 23:20:08 +00:00
"Import data from FILE-NAME.
This removes initial blank and comment lines and then calls
`org-babel-import-elisp-from-file'."
(let ((temp-file (org-babel-temp-file "octave-matlab-")) beg end)
(with-temp-file temp-file
(insert-file-contents file-name)
(re-search-forward "^[ \t]*[^# \t]" nil t)
(if (< (setq beg (point-min))
(setq end (point-at-bol)))
(delete-region beg end)))
(org-babel-import-elisp-from-file temp-file '(16))))
2010-03-18 18:45:39 +00:00
(defun org-babel-octave-read-string (string)
"Strip \\\"s from around octave string"
(if (string-match "^\"\\([^\000]+\\)\"$" string)
(match-string 1 string)
string))
(provide 'ob-octave)
;; arch-tag: d8e5f68b-ba13-440a-a495-b653e989e704
;;; ob-octave.el ends here