:padline insertion aware of placement in file
[org-mode.git] / lisp / ob-io.el
blobaf18f7468c7bf059b53048dd90955e482f283519
1 ;;; ob-io.el --- org-babel functions for Io evaluation
3 ;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
5 ;; Author: Andrzej Lichnerowicz
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
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
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
34 ;;; Code:
35 (require 'ob)
36 (eval-when-compile (require 'cl))
38 (defvar org-babel-tangle-lang-exts) ;; Autoloaded
39 (add-to-list 'org-babel-tangle-lang-exts '("io" . "io"))
40 (defvar org-babel-default-header-args:io '())
41 (defvar org-babel-io-command "io"
42 "Name of the command to use for executing Io code.")
44 (defun org-babel-execute:io (body params)
45 "Execute a block of Io code with org-babel. This function is
46 called by `org-babel-execute-src-block'"
47 (message "executing Io source code block")
48 (let* ((processed-params (org-babel-process-params params))
49 (session (org-babel-io-initiate-session (nth 0 processed-params)))
50 (vars (nth 1 processed-params))
51 (result-params (nth 2 processed-params))
52 (result-type (cdr (assoc :result-type params)))
53 (full-body (org-babel-expand-body:generic
54 body params))
55 (result (org-babel-io-evaluate
56 session full-body result-type result-params)))
58 (org-babel-reassemble-table
59 result
60 (org-babel-pick-name
61 (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
62 (org-babel-pick-name
63 (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
66 (defun org-babel-io-table-or-string (results)
67 "Convert RESULTS into an appropriate elisp value.
68 If RESULTS look like a table, then convert them into an
69 Emacs-lisp table, otherwise return the results as a string."
70 (org-babel-script-escape results))
73 (defvar org-babel-io-wrapper-method
76 ) asString print
80 (defun org-babel-io-evaluate (session body &optional result-type result-params)
81 "Evaluate BODY in external Io process.
82 If RESULT-TYPE equals 'output then return standard output as a string.
83 If RESULT-TYPE equals 'value then return the value of the last statement
84 in BODY as elisp."
85 (when session (error "Sessions are not (yet) supported for Io"))
86 (case result-type
87 (output
88 (if (member "repl" result-params)
89 (org-babel-eval org-babel-io-command body)
90 (let ((src-file (org-babel-temp-file "io-")))
91 (progn (with-temp-file src-file (insert body))
92 (org-babel-eval
93 (concat org-babel-io-command " " src-file) "")))))
94 (value (let* ((src-file (org-babel-temp-file "io-"))
95 (wrapper (format org-babel-io-wrapper-method body)))
96 (with-temp-file src-file (insert wrapper))
97 ((lambda (raw)
98 (org-babel-result-cond result-params
99 raw
100 (org-babel-io-table-or-string raw)))
101 (org-babel-eval
102 (concat org-babel-io-command " " src-file) ""))))))
105 (defun org-babel-prep-session:io (session params)
106 "Prepare SESSION according to the header arguments specified in PARAMS."
107 (error "Sessions are not (yet) supported for Io"))
109 (defun org-babel-io-initiate-session (&optional session)
110 "If there is not a current inferior-process-buffer in SESSION
111 then create. Return the initialized session. Sessions are not
112 supported in Io."
113 nil)
115 (provide 'ob-io)
119 ;;; ob-io.el ends here