2017-06-21 11:20:20 +00:00
|
|
|
;;; ob-shen.el --- Babel Functions for Shen -*- lexical-binding: t; -*-
|
2012-01-03 17:27:21 +00:00
|
|
|
|
2019-01-01 00:59:58 +00:00
|
|
|
;; Copyright (C) 2010-2019 Free Software Foundation, Inc.
|
2012-01-03 17:27:21 +00:00
|
|
|
|
|
|
|
;; Author: Eric Schulte
|
|
|
|
;; Keywords: literate programming, reproducible research, shen
|
2018-03-27 21:34:41 +00:00
|
|
|
;; Homepage: https://orgmode.org
|
2012-01-03 17:27:21 +00:00
|
|
|
|
|
|
|
;; 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
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-03 17:27:21 +00:00
|
|
|
|
|
|
|
;;; 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)
|
|
|
|
|
|
|
|
(declare-function shen-eval-defun "ext:inf-shen" (&optional and-go))
|
2013-11-12 13:06:26 +00:00
|
|
|
(declare-function org-babel-ruby-var-to-ruby "ob-ruby" (var))
|
2012-01-03 17:27:21 +00:00
|
|
|
|
|
|
|
(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."
|
2017-06-21 11:20:20 +00:00
|
|
|
(let ((vars (org-babel--get-vars params)))
|
2012-01-03 17:27:21 +00:00
|
|
|
(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'"
|
|
|
|
(require 'inf-shen)
|
2017-06-21 11:20:20 +00:00
|
|
|
(let* ((result-params (cdr (assq :result-params params)))
|
2012-01-03 17:27:21 +00:00
|
|
|
(full-body (org-babel-expand-body:shen body params)))
|
Address some byte-compiler warnings.
* lisp/org/ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* lisp/org/ob-calc.el (org--var-syms): Rename from `var-syms'.
* lisp/org/ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* lisp/org/ob-table.el (sbe): Move debug declaration.
* lisp/org/org-clock.el (org--msg-extra): Rename from `msg-extra'.
* lisp/org/org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* lisp/org/org-colview.el (org-agenda-overriding-columns-format):
* lisp/org/org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* lisp/org/ob-python.el (py-which-bufname, python-shell-buffer-name):
* lisp/org/ob-haskell.el (org-export-copy-to-kill-ring):
* lisp/org/ob-exp.el (org-link-search-inhibit-query):
* lisp/org/ob-R.el (ess-eval-visibly-p):
* lisp/org/ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* lisp/org/ox-odt.el (org-odt-hfy-face-to-css):
* lisp/org/org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* lisp/org/org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* lisp/org/ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* lisp/org/ob-sqlite.el (org-babel-sqlite-expand-vars):
* lisp/org/ob-sql.el (org-babel-sql-expand-vars):
* lisp/org/ob-shen.el (org-babel-execute:shen):
* lisp/org/ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* lisp/org/ob-scala.el (org-babel-scala-evaluate):
* lisp/org/ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* lisp/org/ob-picolisp.el (org-babel-execute:picolisp):
* lisp/org/ob-perl.el (org-babel-perl-evaluate):
* lisp/org/ob-maxima.el (org-babel-execute:maxima):
* lisp/org/ob-lisp.el (org-babel-execute:lisp):
* lisp/org/ob-java.el (org-babel-execute:java):
* lisp/org/ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* lisp/org/ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* lisp/org/ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* lisp/org/ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* lisp/org/ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* lisp/org/ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* lisp/org/ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 19:11:22 +00:00
|
|
|
(let ((results
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert full-body)
|
|
|
|
(call-interactively #'shen-eval-defun))))
|
2017-06-21 11:20:20 +00:00
|
|
|
(org-babel-result-cond result-params
|
Address some byte-compiler warnings.
* lisp/org/ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* lisp/org/ob-calc.el (org--var-syms): Rename from `var-syms'.
* lisp/org/ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* lisp/org/ob-table.el (sbe): Move debug declaration.
* lisp/org/org-clock.el (org--msg-extra): Rename from `msg-extra'.
* lisp/org/org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* lisp/org/org-colview.el (org-agenda-overriding-columns-format):
* lisp/org/org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* lisp/org/ob-python.el (py-which-bufname, python-shell-buffer-name):
* lisp/org/ob-haskell.el (org-export-copy-to-kill-ring):
* lisp/org/ob-exp.el (org-link-search-inhibit-query):
* lisp/org/ob-R.el (ess-eval-visibly-p):
* lisp/org/ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* lisp/org/ox-odt.el (org-odt-hfy-face-to-css):
* lisp/org/org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* lisp/org/org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* lisp/org/ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* lisp/org/ob-sqlite.el (org-babel-sqlite-expand-vars):
* lisp/org/ob-sql.el (org-babel-sql-expand-vars):
* lisp/org/ob-shen.el (org-babel-execute:shen):
* lisp/org/ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* lisp/org/ob-scala.el (org-babel-scala-evaluate):
* lisp/org/ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* lisp/org/ob-picolisp.el (org-babel-execute:picolisp):
* lisp/org/ob-perl.el (org-babel-perl-evaluate):
* lisp/org/ob-maxima.el (org-babel-execute:maxima):
* lisp/org/ob-lisp.el (org-babel-execute:lisp):
* lisp/org/ob-java.el (org-babel-execute:java):
* lisp/org/ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* lisp/org/ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* lisp/org/ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* lisp/org/ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* lisp/org/ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* lisp/org/ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* lisp/org/ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 19:11:22 +00:00
|
|
|
results
|
|
|
|
(condition-case nil (org-babel-script-escape results)
|
|
|
|
(error results))))))
|
2012-01-03 17:27:21 +00:00
|
|
|
|
|
|
|
(provide 'ob-shen)
|
|
|
|
;;; ob-shen.el ends here
|