More tweaks of skeleton documentation wrt \n behavior at bol/eol.
[bpt/emacs.git] / lisp / org / ob-shen.el
CommitLineData
e66ba1df
BG
1;;; ob-shen.el --- org-babel functions for Shen
2
ba318903 3;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
e66ba1df
BG
4
5;; Author: Eric Schulte
6;; Keywords: literate programming, reproducible research, shen
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
26;; Currently this only works using session evaluation as there is no
27;; defined method for executing shen code outside of a session.
28
29;;; Requirements:
30
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
34
35;;; Code:
36(require 'ob)
37
38(declare-function shen-eval-defun "ext:inf-shen" (&optional and-go))
271672fa 39(declare-function org-babel-ruby-var-to-ruby "ob-ruby" (var))
e66ba1df
BG
40
41(defvar org-babel-default-header-args:shen '()
42 "Default header arguments for shen code blocks.")
43
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)))
55
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)))
61
62(defun org-babel-execute:shen (body params)
63 "Execute a block of Shen code with org-babel.
64This 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)))
666ffc7e
SM
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))))))
e66ba1df
BG
77
78(provide 'ob-shen)
79;;; ob-shen.el ends here