summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleh Krehel <ohwoeowho@gmail.com>2013-10-03 16:23:16 (GMT)
committer Eric Schulte <schulte.eric@gmail.com>2013-10-03 19:06:28 (GMT)
commit7429ceaa0c99c5386b1174220f3a3bd730fa28b6 (patch)
tree3425641c2d54afafacf8cbb80b0869086c688153
parent2020009cc93dd1320775fe57c29d2c831b056a3e (diff)
downloadorg-mode-7429ceaa0c99c5386b1174220f3a3bd730fa28b6.zip
org-mode-7429ceaa0c99c5386b1174220f3a3bd730fa28b6.tar.gz
ob-clojure.el: switch to nREPL as the main method of evaluating Clojure.
Get the old behavior with: (defalias 'org-babel-execute:clojure 'org-babel--execute-clojure-slime)
-rw-r--r--lisp/ob-clojure.el34
1 files changed, 26 insertions, 8 deletions
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index bc2bbc0..3b82f0a 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -2,8 +2,8 @@
;; Copyright (C) 2009-2013 Free Software Foundation, Inc.
-;; Author: Joel Boehland
-;; Eric Schulte
+;; Author: Joel Boehland, Eric Schulte, Oleh Krehel
+;;
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
@@ -24,20 +24,26 @@
;;; Commentary:
-;;; support for evaluating clojure code, relies on slime for all eval
+;;; support for evaluating clojure code, relies either on slime or
+;;; on nrepl for all eval
;;; Requirements:
;;; - clojure (at least 1.2.0)
;;; - clojure-mode
-;;; - slime
+;;; - either slime or nrepl
-;;; By far, the best way to install these components is by following
-;;; the directions as set out by Phil Hagelberg (Technomancy) on the
-;;; web page: http://technomancy.us/126
+;;; For SLIME-way, the best way to install these components is by
+;;; following the directions as set out by Phil Hagelberg (Technomancy)
+;;; on the web page: http://technomancy.us/126
+
+;;; For nREPL-way:
+;;; get clojure is with https://github.com/technomancy/leiningen
+;;; get nrepl from MELPA (clojure-mode is a dependency).
;;; Code:
(require 'ob)
+(require 'ob-tangle)
(declare-function slime-eval "ext:slime" (sexp &optional package))
@@ -72,7 +78,7 @@
(format "(clojure.core/with-out-str %s)" body))
(t body))))
-(defun org-babel-execute:clojure (body params)
+(defun org-babel--execute-clojure-slime (body params)
"Execute a block of Clojure code with Babel."
(require 'slime)
(with-temp-buffer
@@ -88,6 +94,18 @@
,(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)
+
(provide 'ob-clojure)