Update copyright notices for 2013.
[bpt/emacs.git] / lisp / org / ob-io.el
CommitLineData
8223b1d2
BG
1;;; ob-io.el --- org-babel functions for Io evaluation
2
ab422c4d 3;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
8223b1d2
BG
4
5;; Author: Andrzej Lichnerowicz
6;; Keywords: literate programming, reproducible research
7;; Homepage: http://orgmode.org
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25;; Currently only supports the external execution. No session support yet.
26;; :results output -- runs in scripting mode
27;; :results output repl -- runs in repl mode
28
29;;; Requirements:
30;; - Io language :: http://iolanguage.org/
31;; - Io major mode :: Can be installed from Io sources
32;; https://github.com/stevedekorte/io/blob/master/extras/SyntaxHighlighters/Emacs/io-mode.el
33
34;;; Code:
35(require 'ob)
36(require 'ob-ref)
37(require 'ob-comint)
38(require 'ob-eval)
39(eval-when-compile (require 'cl))
40
bdebdb64 41(defvar org-babel-tangle-lang-exts) ;; Autoloaded
8223b1d2
BG
42(add-to-list 'org-babel-tangle-lang-exts '("io" . "io"))
43(defvar org-babel-default-header-args:io '())
44(defvar org-babel-io-command "io"
45 "Name of the command to use for executing Io code.")
46
8223b1d2
BG
47(defun org-babel-execute:io (body params)
48 "Execute a block of Io code with org-babel. This function is
49called by `org-babel-execute-src-block'"
50 (message "executing Io source code block")
51 (let* ((processed-params (org-babel-process-params params))
52 (session (org-babel-io-initiate-session (nth 0 processed-params)))
53 (vars (nth 1 processed-params))
54 (result-params (nth 2 processed-params))
55 (result-type (cdr (assoc :result-type params)))
56 (full-body (org-babel-expand-body:generic
57 body params))
58 (result (org-babel-io-evaluate
59 session full-body result-type result-params)))
60
61 (org-babel-reassemble-table
62 result
63 (org-babel-pick-name
64 (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
65 (org-babel-pick-name
66 (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
67
68
69(defun org-babel-io-table-or-string (results)
70 "Convert RESULTS into an appropriate elisp value.
71If RESULTS look like a table, then convert them into an
72Emacs-lisp table, otherwise return the results as a string."
73 (org-babel-script-escape results))
74
75
76(defvar org-babel-io-wrapper-method
77 "(
78%s
79) asString print
80")
81
82
83(defun org-babel-io-evaluate (session body &optional result-type result-params)
84 "Evaluate BODY in external Io process.
85If RESULT-TYPE equals 'output then return standard output as a string.
86If RESULT-TYPE equals 'value then return the value of the last statement
87in BODY as elisp."
88 (when session (error "Sessions are not (yet) supported for Io"))
89 (case result-type
90 (output
91 (if (member "repl" result-params)
92 (org-babel-eval org-babel-io-command body)
93 (let ((src-file (org-babel-temp-file "io-")))
94 (progn (with-temp-file src-file (insert body))
95 (org-babel-eval
96 (concat org-babel-io-command " " src-file) "")))))
97 (value (let* ((src-file (org-babel-temp-file "io-"))
98 (wrapper (format org-babel-io-wrapper-method body)))
99 (with-temp-file src-file (insert wrapper))
100 ((lambda (raw)
101 (if (member "code" result-params)
102 raw
103 (org-babel-io-table-or-string raw)))
104 (org-babel-eval
105 (concat org-babel-io-command " " src-file) ""))))))
106
107
108(defun org-babel-prep-session:io (session params)
109 "Prepare SESSION according to the header arguments specified in PARAMS."
110 (error "Sessions are not (yet) supported for Io"))
111
112(defun org-babel-io-initiate-session (&optional session)
113 "If there is not a current inferior-process-buffer in SESSION
114then create. Return the initialized session. Sessions are not
115supported in Io."
116 nil)
117
118(provide 'ob-io)
119
120
121
122;;; ob-io.el ends here