summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2013-10-03 19:25:46 (GMT)
committer Eric Schulte <schulte.eric@gmail.com>2013-10-03 19:25:46 (GMT)
commitee6c792ec7657e50524d78d309538e7e58bb2989 (patch)
tree789fbcb0daf20ae9d23c03035aa5999ca66f2297
parent7429ceaa0c99c5386b1174220f3a3bd730fa28b6 (diff)
downloadorg-mode-ee6c792ec7657e50524d78d309538e7e58bb2989.zip
org-mode-ee6c792ec7657e50524d78d309538e7e58bb2989.tar.gz
ob-clojure nrepl customization variable
- ensure body is expanded for n-repl as well - declare n-repl functions - remove require ob-tangle from ob-clojure * lisp/ob-clojure.el (org-babel-clojure-backend): Customization variable to select clojure backend (nrepl-eval): Declared function. (nrepl-current-connection-buffer): Declared function. (org-babel-execute:clojure): Execution now uses customized backend.
-rw-r--r--lisp/ob-clojure.el59
1 files changed, 32 insertions, 27 deletions
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 3b82f0a..255fe8d 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -43,9 +43,10 @@
;;; Code:
(require 'ob)
-(require 'ob-tangle)
(declare-function slime-eval "ext:slime" (sexp &optional package))
+(declare-function nrepl-current-connection-buffer "ext:nrepl" ())
+(declare-function nrepl-eval "ext:nrepl" (body))
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
@@ -53,6 +54,11 @@
(defvar org-babel-default-header-args:clojure '())
(defvar org-babel-header-args:clojure '((package . :any)))
+(defcustom org-babel-clojure-backend 'nrepl
+ "Backend used to evaluate Clojure code blocks."
+ :group 'org-babel
+ :type 'symbol)
+
(defun org-babel-expand-body:clojure (body params)
"Expand BODY according to PARAMS, return the expanded body."
(let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
@@ -78,33 +84,32 @@
(format "(clojure.core/with-out-str %s)" body))
(t body))))
-(defun org-babel--execute-clojure-slime (body params)
+(defun org-babel-execute:clojure (body params)
"Execute a block of Clojure code with Babel."
- (require 'slime)
- (with-temp-buffer
- (insert (org-babel-expand-body:clojure body params))
- ((lambda (result)
- (let ((result-params (cdr (assoc :result-params params))))
- (org-babel-result-cond result-params
- result
- (condition-case nil (org-babel-script-escape result)
- (error result)))))
- (slime-eval
- `(swank:eval-and-grab-output
- ,(buffer-substring-no-properties (point-min) (point-max)))
- (cdr (assoc :package params))))))
-
-(defun org-babel--execute-clojure-nrepl (body params)
- "Execute a block of Clojure code with Babel and nREPL."
- (require 'nrepl)
- (if (nrepl-current-connection-buffer)
- (let* ((result (nrepl-eval body))
- (s (plist-get result :stdout))
- (r (plist-get result :value)))
- (if s (concat s "\n" r) r))
- (error "nREPL not connected! Use M-x nrepl-jack-in.")))
-
-(defalias 'org-babel-execute:clojure 'org-babel--execute-clojure-nrepl)
+ (let ((expanded (org-babel-expand-body:clojure body params)))
+ (case org-babel-clojure-backend
+ (slime
+ (require 'slime)
+ (with-temp-buffer
+ (insert expanded)
+ ((lambda (result)
+ (let ((result-params (cdr (assoc :result-params params))))
+ (org-babel-result-cond result-params
+ result
+ (condition-case nil (org-babel-script-escape result)
+ (error result)))))
+ (slime-eval
+ `(swank:eval-and-grab-output
+ ,(buffer-substring-no-properties (point-min) (point-max)))
+ (cdr (assoc :package params))))))
+ (nrepl
+ (require 'nrepl)
+ (if (nrepl-current-connection-buffer)
+ (let* ((result (nrepl-eval expanded))
+ (s (plist-get result :stdout))
+ (r (plist-get result :value)))
+ (if s (concat s "\n" r) r))
+ (error "nREPL not connected! Use M-x nrepl-jack-in."))))))
(provide 'ob-clojure)