For those people (like myself) who do a lot of Literate Programming in 
Emacs using Clojure and org-babel, migrating to nrepl and nrepl.el is 
somewhat non-trivial. This is because the existing Clojure support in 
org-babel (ob-clojure.el) relies on slime and swank-clojure when running 
org-babel-execute-src-block (which redirects to org-babel-execute:clojure 
in ob-clojure.el).

So clearly this is actually an issue for both nrepl.el and ob-clojure.el, 
not simply one or the other. All the same, I've hacked together a simple 
workaround that fixes the problem and makes Literate Programming under 
nrepl possible once again. If there is some slick way this could be worked 
into nrepl.el's codebase that wouldn't break its existing behavior (as this 
does), I'd be excited to see it.

Here we go:

;; Patch result table rendering bug in ob-clojure (NREPL version)
(defun nrepl-send-request-sync (request)
  "Send a request to the backend synchronously (discouraged).
The result is a plist with keys :value, :stderr and :stdout."
  (with-current-buffer "*nrepl-connection*"
    (setq nrepl-sync-response nil)
    (nrepl-send-request request (nrepl-sync-request-handler 
(current-buffer)))
    (while (not (plist-get nrepl-sync-response :done))
      (accept-process-output))
    nrepl-sync-response))

(defun org-babel-execute:clojure (body params)
  "Execute a block of Clojure code with Babel."
  (let ((result-plist (nrepl-send-string-sync 
(org-babel-expand-body:clojure body params) nrepl-buffer-ns))
        (result-type  (cdr (assoc :result-type params))))
    (org-babel-script-escape
     (cond ((eq result-type 'value)  (plist-get result-plist :value))
           ((eq result-type 'output) (plist-get result-plist :value))
           (t                        (message "Unknown :results type!"))))))

Have fun!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to