Mercurial > emacs
comparison lisp/org/ob-clojure.el @ 111506:5cb272c831e8
Install org-mode version 7.3
author | Carsten Dominik <carsten.dominik@gmail.com> |
---|---|
date | Thu, 11 Nov 2010 22:10:19 -0600 |
parents | a150e8a14679 |
children | a7740098b594 |
comparison
equal
deleted
inserted
replaced
111505:62aa3653746a | 111506:5cb272c831e8 |
---|---|
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Joel Boehland | 5 ;; Author: Joel Boehland |
6 ;; Keywords: literate programming, reproducible research | 6 ;; Keywords: literate programming, reproducible research |
7 ;; Homepage: http://orgmode.org | 7 ;; Homepage: http://orgmode.org |
8 ;; Version: 7.01 | 8 ;; Version: 7.3 |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 | 11 |
12 ;; GNU Emacs is free software: you can redistribute it and/or modify | 12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
13 ;; it under the terms of the GNU General Public License as published by | 13 ;; it under the terms of the GNU General Public License as published by |
43 (eval-when-compile (require 'cl)) | 43 (eval-when-compile (require 'cl)) |
44 | 44 |
45 (declare-function slime-eval-async "ext:slime" (sexp &optional cont package)) | 45 (declare-function slime-eval-async "ext:slime" (sexp &optional cont package)) |
46 (declare-function slime-eval "ext:slime" (sexp &optional package)) | 46 (declare-function slime-eval "ext:slime" (sexp &optional package)) |
47 (declare-function swank-clojure-concat-paths "ext:slime" (paths)) | 47 (declare-function swank-clojure-concat-paths "ext:slime" (paths)) |
48 (declare-function org-babel-ref-variables "ext:slime" (params)) | |
49 (declare-function slime "ext:slime" (&optional command coding-system)) | 48 (declare-function slime "ext:slime" (&optional command coding-system)) |
50 (declare-function slime-output-buffer "ext:slime" (&optional noprompt)) | 49 (declare-function slime-output-buffer "ext:slime" (&optional noprompt)) |
51 (declare-function slime-filter-buffers "ext:slime" (predicate)) | 50 (declare-function slime-filter-buffers "ext:slime" (predicate)) |
52 | 51 |
53 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj")) | 52 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj")) |
90 (defvar swank-clojure-extra-vm-args) | 89 (defvar swank-clojure-extra-vm-args) |
91 (defvar swank-clojure-library-paths) | 90 (defvar swank-clojure-library-paths) |
92 (defvar swank-clojure-extra-classpaths) | 91 (defvar swank-clojure-extra-classpaths) |
93 (defun org-babel-clojure-babel-clojure-cmd () | 92 (defun org-babel-clojure-babel-clojure-cmd () |
94 "Create the command to start clojure according to current settings." | 93 "Create the command to start clojure according to current settings." |
95 (if (and (not swank-clojure-binary) (not swank-clojure-classpath)) | 94 (or (when swank-clojure-binary |
95 (if (listp swank-clojure-binary) | |
96 swank-clojure-binary | |
97 (list swank-clojure-binary))) | |
98 (when swank-clojure-classpath | |
99 (delq | |
100 nil | |
101 (append | |
102 (list swank-clojure-java-path) | |
103 swank-clojure-extra-vm-args | |
104 (list | |
105 (when swank-clojure-library-paths | |
106 (concat "-Djava.library.path=" | |
107 (swank-clojure-concat-paths swank-clojure-library-paths))) | |
108 "-classpath" | |
109 (swank-clojure-concat-paths | |
110 (append | |
111 swank-clojure-classpath | |
112 swank-clojure-extra-classpaths)) | |
113 "clojure.main")))) | |
96 (error "%s" (concat "You must specifiy either a `swank-clojure-binary' " | 114 (error "%s" (concat "You must specifiy either a `swank-clojure-binary' " |
97 "or a `swank-clojure-jar-path'")) | 115 "or a `swank-clojure-classpath'")))) |
98 (if swank-clojure-binary | |
99 (if (listp swank-clojure-binary) | |
100 swank-clojure-binary | |
101 (list swank-clojure-binary)) | |
102 (delq | |
103 nil | |
104 (append | |
105 (list swank-clojure-java-path) | |
106 swank-clojure-extra-vm-args | |
107 (list | |
108 (when swank-clojure-library-paths | |
109 (concat "-Djava.library.path=" | |
110 (swank-clojure-concat-paths swank-clojure-library-paths))) | |
111 "-classpath" | |
112 (swank-clojure-concat-paths | |
113 (append | |
114 swank-clojure-classpath | |
115 swank-clojure-extra-classpaths)) | |
116 "clojure.main")))))) | |
117 | 116 |
118 (defun org-babel-clojure-table-or-string (results) | 117 (defun org-babel-clojure-table-or-string (results) |
119 "Convert RESULTS to an elisp value. | 118 "Convert RESULTS to an elisp value. |
120 If RESULTS looks like a table, then convert to an Emacs-lisp | 119 If RESULTS looks like a table, then convert to an Emacs-lisp |
121 table, otherwise return the results as a string." | 120 table, otherwise return the results as a string." |
153 | 152 |
154 (defun org-babel-prep-session:clojure (session params) | 153 (defun org-babel-prep-session:clojure (session params) |
155 "Prepare SESSION according to the header arguments specified in PARAMS." | 154 "Prepare SESSION according to the header arguments specified in PARAMS." |
156 (require 'slime) (require 'swank-clojure) | 155 (require 'slime) (require 'swank-clojure) |
157 (let* ((session-buf (org-babel-clojure-initiate-session session)) | 156 (let* ((session-buf (org-babel-clojure-initiate-session session)) |
158 (vars (org-babel-ref-variables params)) | 157 (vars (mapcar #'cdr (org-babel-get-header params :var))) |
159 (var-lines (mapcar ;; define any top level session variables | 158 (var-lines (mapcar ;; define any top level session variables |
160 (lambda (pair) | 159 (lambda (pair) |
161 (format "(def %s %s)\n" (car pair) | 160 (format "(def %s %s)\n" (car pair) |
162 (org-babel-clojure-var-to-clojure (cdr pair)))) | 161 (org-babel-clojure-var-to-clojure (cdr pair)))) |
163 vars))) | 162 vars))) |
259 (let ((cmd (format "%s -" (mapconcat #'identity | 258 (let ((cmd (format "%s -" (mapconcat #'identity |
260 (org-babel-clojure-babel-clojure-cmd) | 259 (org-babel-clojure-babel-clojure-cmd) |
261 " ")))) | 260 " ")))) |
262 (case result-type | 261 (case result-type |
263 (output (org-babel-eval cmd body)) | 262 (output (org-babel-eval cmd body)) |
264 (value (let* ((tmp-file (make-temp-file "org-babel-clojure-results-"))) | 263 (value (let* ((tmp-file (org-babel-temp-file "clojure-"))) |
265 (org-babel-eval cmd (format org-babel-clojure-wrapper-method | 264 (org-babel-eval |
266 body tmp-file tmp-file)) | 265 cmd |
266 (format | |
267 org-babel-clojure-wrapper-method | |
268 body | |
269 (org-babel-process-file-name tmp-file 'noquote))) | |
267 (org-babel-clojure-table-or-string | 270 (org-babel-clojure-table-or-string |
268 (org-babel-eval-read-file tmp-file))))))) | 271 (org-babel-eval-read-file tmp-file))))))) |
269 | 272 |
270 (defun org-babel-clojure-evaluate-session (buffer body &optional result-type) | 273 (defun org-babel-clojure-evaluate-session (buffer body &optional result-type) |
271 "Evaluate the body in the context of a clojure session." | 274 "Evaluate the body in the context of a clojure session." |
288 return the value of the last statement in BODY as elisp." | 291 return the value of the last statement in BODY as elisp." |
289 (if buffer | 292 (if buffer |
290 (org-babel-clojure-evaluate-session buffer body result-type) | 293 (org-babel-clojure-evaluate-session buffer body result-type) |
291 (org-babel-clojure-evaluate-external-process buffer body result-type))) | 294 (org-babel-clojure-evaluate-external-process buffer body result-type))) |
292 | 295 |
293 (defun org-babel-expand-body:clojure (body params &optional processed-params) | 296 (defun org-babel-expand-body:clojure (body params) |
294 "Expand BODY according to PARAMS, return the expanded body." | 297 "Expand BODY according to PARAMS, return the expanded body." |
295 (org-babel-clojure-build-full-form | 298 (org-babel-clojure-build-full-form |
296 body (nth 1 (or processed-params (org-babel-process-params params))))) | 299 body (mapcar #'cdr (org-babel-get-header params :var)))) |
297 | 300 |
298 (defun org-babel-execute:clojure (body params) | 301 (defun org-babel-execute:clojure (body params) |
299 "Execute a block of Clojure code." | 302 "Execute a block of Clojure code." |
300 (require 'slime) (require 'swank-clojure) | 303 (require 'slime) (require 'swank-clojure) |
301 (let* ((processed-params (org-babel-process-params params)) | 304 (let* ((body (org-babel-expand-body:clojure body params)) |
302 (body (org-babel-expand-body:clojure body params processed-params)) | |
303 (session (org-babel-clojure-initiate-session | 305 (session (org-babel-clojure-initiate-session |
304 (first processed-params)))) | 306 (cdr (assoc :session params))))) |
305 (org-babel-reassemble-table | 307 (org-babel-reassemble-table |
306 (org-babel-clojure-evaluate session body (nth 3 processed-params)) | 308 (org-babel-clojure-evaluate session body (cdr (assoc :result-type params))) |
307 (org-babel-pick-name | 309 (org-babel-pick-name |
308 (nth 4 processed-params) (cdr (assoc :colnames params))) | 310 (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) |
309 (org-babel-pick-name | 311 (org-babel-pick-name |
310 (nth 5 processed-params) (cdr (assoc :rownames params)))))) | 312 (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))) |
311 | 313 |
312 (provide 'ob-clojure) | 314 (provide 'ob-clojure) |
313 | 315 |
314 ;; arch-tag: a43b33f2-653e-46b1-ac56-2805cf05b7d1 | 316 ;; arch-tag: a43b33f2-653e-46b1-ac56-2805cf05b7d1 |
315 | 317 |