diff options
author | Eric Schulte <schulte.eric@gmail.com> | 2011-10-06 19:54:22 -0600 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2011-10-06 19:55:47 -0600 |
commit | 53573d6e2809cba6c36040bb009d99b97c4808f3 (patch) | |
tree | 0de82d68bc9e679c0fe57abc130293797d0dfe38 | |
parent | 5147f6b00856edc026f873feb3dbe500fde25741 (diff) | |
download | org-mode-53573d6e2809cba6c36040bb009d99b97c4808f3.tar.gz |
adding initial support for evaluation of shen code blocks
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | lisp/ob-shen.el | 76 | ||||
-rw-r--r-- | lisp/org.el | 1 |
3 files changed, 79 insertions, 1 deletions
@@ -158,7 +158,8 @@ LISPF = org.el \ ob-js.el \ ob-scheme.el \ ob-lilypond.el \ - ob-java.el + ob-java.el \ + ob-shen.el LISPFILES0 = $(LISPF:%=lisp/%) LISPFILES = $(LISPFILES0) lisp/org-install.el diff --git a/lisp/ob-shen.el b/lisp/ob-shen.el new file mode 100644 index 0000000..123e39e --- /dev/null +++ b/lisp/ob-shen.el @@ -0,0 +1,76 @@ +;;; ob-shen.el --- org-babel functions for Shen + +;; Copyright (C) 2010-2011 Free Software Foundation + +;; Author: Eric Schulte +;; Keywords: literate programming, reproducible research, shen +;; Homepage: http://orgmode.org + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Currently this only works using session evaluation as there is no +;; defined method for executing shen code outside of a session. + +;;; Requirements: + +;; - shen-mode and inf-shen will soon be available through the GNU +;; elpa, however in the interim they are available at +;; https://github.com/eschulte/shen-mode + +;;; Code: +(require 'ob) +(require 'inf-shen) + +(defvar org-babel-default-header-args:shen '() + "Default header arguments for shen code blocks.") + +(defun org-babel-expand-body:shen (body params) + "Expand BODY according to PARAMS, return the expanded body." + (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))) + (if (> (length vars) 0) + (concat "(let " + (mapconcat (lambda (var) + (format "%s %s" (car var) + (org-babel-shen-var-to-shen (cdr var)))) + vars " ") + body ")") + body))) + +(defun org-babel-shen-var-to-shen (var) + "Convert VAR into a shen variable." + (if (listp var) + (concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var " ") "]") + (format "%S" var))) + +(defun org-babel-execute:shen (body params) + "Execute a block of Shen code with org-babel. +This function is called by `org-babel-execute-src-block'" + (let* ((result-type (cdr (assoc :result-type params))) + (full-body (org-babel-expand-body:shen body params))) + ((lambda (results) + (if (or (member 'scalar result-params) + (member 'verbatim result-params)) + results + (condition-case nil (org-babel-script-escape results) + (error result)))) + (with-temp-buffer + (insert full-body) + (call-interactively #'shen-eval-defun))))) + +(provide 'ob-shen) +;;; ob-shen.el ends here diff --git a/lisp/org.el b/lisp/org.el index ef7b4da..4a11fc0 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -185,6 +185,7 @@ requirements) is loaded." (const :tag "Scheme" scheme) (const :tag "Screen" screen) (const :tag "Shell Script" sh) + (const :tag "Shen" shen) (const :tag "Sql" sql) (const :tag "Sqlite" sqlite)) :value-type (boolean :tag "Activate" :value t))) |