org.el: Fix bug about filling message headers and citations
[org-mode.git] / lisp / ob-shen.el
blob8f4b13217c69935441024b3235221475fc2f1ebd
1 ;;; ob-shen.el --- org-babel functions for Shen
3 ;; Copyright (C) 2010-2012 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))
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)
47 (concat "(let "
48 (mapconcat (lambda (var)
49 (format "%s %s" (car var)
50 (org-babel-shen-var-to-shen (cdr var))))
51 vars " ")
52 body ")")
53 body)))
55 (defun org-babel-shen-var-to-shen (var)
56 "Convert VAR into a shen variable."
57 (if (listp var)
58 (concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var " ") "]")
59 (format "%S" 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'"
64 (require 'inf-shen)
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)))
68 ((lambda (results)
69 (if (or (member 'scalar result-params)
70 (member 'verbatim result-params))
71 results
72 (condition-case nil (org-babel-script-escape results)
73 (error results))))
74 (with-temp-buffer
75 (insert full-body)
76 (call-interactively #'shen-eval-defun)))))
78 (provide 'ob-shen)
79 ;;; ob-shen.el ends here