`org-add-planning-info' need not be interactive
[org-mode/org-tableheadings.git] / lisp / ob-shen.el
blobe40e45ccb1e762ca142512a5baf03afeb4dc6261
1 ;;; ob-shen.el --- org-babel functions for Shen
3 ;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research, shen
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:
26 ;; Currently this only works using session evaluation as there is no
27 ;; defined method for executing shen code outside of a session.
29 ;;; Requirements:
31 ;; - shen-mode and inf-shen will soon be available through the GNU
32 ;; elpa, however in the interim they are available at
33 ;; https://github.com/eschulte/shen-mode
35 ;;; Code:
36 (require 'ob)
38 (declare-function shen-eval-defun "ext:inf-shen" (&optional and-go))
39 (declare-function org-babel-ruby-var-to-ruby "ob-ruby" (var))
41 (defvar org-babel-default-header-args:shen '()
42 "Default header arguments for shen code blocks.")
44 (defun org-babel-expand-body:shen (body params)
45 "Expand BODY according to PARAMS, return the expanded body."
46 (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
47 (if (> (length vars) 0)
48 (concat "(let "
49 (mapconcat (lambda (var)
50 (format "%s %s" (car var)
51 (org-babel-shen-var-to-shen (cdr var))))
52 vars " ")
53 body ")")
54 body)))
56 (defun org-babel-shen-var-to-shen (var)
57 "Convert VAR into a shen variable."
58 (if (listp var)
59 (concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var " ") "]")
60 (format "%S" var)))
62 (defun org-babel-execute:shen (body params)
63 "Execute a block of Shen code with org-babel.
64 This function is called by `org-babel-execute-src-block'"
65 (require 'inf-shen)
66 (let* ((result-type (cdr (assoc :result-type params)))
67 (result-params (cdr (assoc :result-params params)))
68 (full-body (org-babel-expand-body:shen body params)))
69 (let ((results
70 (with-temp-buffer
71 (insert full-body)
72 (call-interactively #'shen-eval-defun))))
73 (org-babel-result-cond result-params
74 results
75 (condition-case nil (org-babel-script-escape results)
76 (error results))))))
78 (provide 'ob-shen)
79 ;;; ob-shen.el ends here