commit | author | age
|
76bbd0
|
1 |
;;; ob-shen.el --- Babel Functions for Shen -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2010-2018 Free Software Foundation, Inc. |
|
4 |
|
|
5 |
;; Author: Eric Schulte |
|
6 |
;; Keywords: literate programming, reproducible research, shen |
|
7 |
;; Homepage: https://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 <https://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)) |
|
39 |
(declare-function org-babel-ruby-var-to-ruby "ob-ruby" (var)) |
|
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 (org-babel--get-vars params))) |
|
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. |
|
64 |
This function is called by `org-babel-execute-src-block'" |
|
65 |
(require 'inf-shen) |
|
66 |
(let* ((result-params (cdr (assq :result-params params))) |
|
67 |
(full-body (org-babel-expand-body:shen body params))) |
|
68 |
(let ((results |
|
69 |
(with-temp-buffer |
|
70 |
(insert full-body) |
|
71 |
(call-interactively #'shen-eval-defun)))) |
|
72 |
(org-babel-result-cond result-params |
|
73 |
results |
|
74 |
(condition-case nil (org-babel-script-escape results) |
|
75 |
(error results)))))) |
|
76 |
|
|
77 |
(provide 'ob-shen) |
|
78 |
;;; ob-shen.el ends here |