1 ;;; ob-shen.el --- org-babel functions for Shen
3 ;; Copyright (C) 2010-2011 Free Software Foundation
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/>.
26 ;; Currently this only works using session evaluation as there is no
27 ;; defined method for executing shen code outside of a session.
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
38 (declare-function shen-eval-defun
"ext:inf-shen" (&optional and-go
))
40 (defvar org-babel-default-header-args
:shen
'()
41 "Default header arguments for shen code blocks.")
43 (defun org-babel-expand-body:shen
(body params
)
44 "Expand BODY according to PARAMS, return the expanded body."
45 (let ((vars (mapcar #'cdr
(org-babel-get-header params
:var
))))
46 (if (> (length vars
) 0)
48 (mapconcat (lambda (var)
49 (format "%s %s" (car var
)
50 (org-babel-shen-var-to-shen (cdr var
))))
55 (defun org-babel-shen-var-to-shen (var)
56 "Convert VAR into a shen variable."
58 (concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var
" ") "]")
61 (defun org-babel-execute:shen
(body params
)
62 "Execute a block of Shen code with org-babel.
63 This function is called by `org-babel-execute-src-block'"
65 (let* ((result-type (cdr (assoc :result-type params
)))
66 (result-params (cdr (assoc :result-params params
)))
67 (full-body (org-babel-expand-body:shen body params
)))
69 (if (or (member 'scalar result-params
)
70 (member 'verbatim result-params
))
72 (condition-case nil
(org-babel-script-escape results
)
76 (call-interactively #'shen-eval-defun
)))))
79 ;;; ob-shen.el ends here