Mercurial > emacs
annotate lisp/org/ob-clojure.el @ 112442:76fa839f455e
* Makefile.in (MAKEINFO): Now controlled by `configure'.
(MAKEINFO_OPTS): New variable. Use it where appropriate.
(ENVADD): New variable to control texi2dvi and texi2pdf.
author | Werner Lemberg <wl@gnu.org> |
---|---|
date | Sun, 23 Jan 2011 11:22:21 +0100 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
1 ;;; ob-clojure.el --- org-babel functions for clojure evaluation |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
2 |
112275
6378d1b57038
Add 2011 to remaining FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
111880
diff
changeset
|
3 ;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
4 |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
5 ;; Author: Joel Boehland, Eric Schulte |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
6 ;; Keywords: literate programming, reproducible research |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
7 ;; Homepage: http://orgmode.org |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
8 ;; Version: 7.4 |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
9 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
11 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
15 ;; (at your option) any later version. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
16 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
21 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
24 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
25 ;;; Commentary: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
26 |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
27 ;;; support for evaluating clojure code, relies on slime for all eval |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
28 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
29 ;;; Requirements: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
30 |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
31 ;;; - clojure (at least 1.2.0) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
32 ;;; - clojure-mode |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
33 ;;; - slime |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
34 ;;; - swank-clojure |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
35 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
36 ;;; By far, the best way to install these components is by following |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
37 ;;; the directions as set out by Phil Hagelberg (Technomancy) on the |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
38 ;;; web page: http://technomancy.us/126 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
39 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
40 ;;; Code: |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
41 (require 'ob) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
42 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
43 (declare-function slime-eval "ext:slime" (sexp &optional package)) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
44 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
45 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj")) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
46 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
47 (defvar org-babel-default-header-args:clojure '()) |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
48 (defvar org-babel-header-arg-names:clojure '(package)) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
49 |
111506
5cb272c831e8
Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
109462
diff
changeset
|
50 (defun org-babel-expand-body:clojure (body params) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
51 "Expand BODY according to PARAMS, return the expanded body." |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
52 (let* ((vars (mapcar #'cdr (org-babel-get-header params :var))) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
53 (result-params (cdr (assoc :result-params params))) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
54 (print-level nil) (print-length nil) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
55 (body (org-babel-trim |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
56 (if (> (length vars) 0) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
57 (concat "(let [" |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
58 (mapconcat |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
59 (lambda (var) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
60 (format "%S (quote %S)" (car var) (cdr var))) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
61 vars "\n ") |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
62 "]\n" body ")") |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
63 body)))) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
64 (if (or (member "code" result-params) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
65 (member "pp" result-params)) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
66 (format (concat "(let [org-mode-print-catcher (java.io.StringWriter.)]" |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
67 "(clojure.pprint/with-pprint-dispatch %s-dispatch" |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
68 "(clojure.pprint/pprint %s org-mode-print-catcher)" |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
69 "(str org-mode-print-catcher)))") |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
70 (if (member "code" result-params) "code" "simple") body) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
71 body))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
72 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
73 (defun org-babel-execute:clojure (body params) |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
74 "Execute a block of Clojure code with Babel." |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
75 (require 'slime) (require 'swank-clojure) |
111880
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
76 (with-temp-buffer |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
77 (insert (org-babel-expand-body:clojure body params)) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
78 (read |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
79 (slime-eval |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
80 `(swank:interactive-eval-region |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
81 ,(buffer-substring-no-properties (point-min) (point-max))) |
a7740098b594
Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents:
111506
diff
changeset
|
82 (cdr (assoc :package params)))))) |
109462
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
83 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
84 (provide 'ob-clojure) |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
85 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
86 |
a150e8a14679
Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
87 ;;; ob-clojure.el ends here |