Re: [nrepl-el] nrepl with org-babel Clojure?

277 views
Skip to first unread message

Tim King

unread,
Sep 4, 2012, 10:27:38 AM9/4/12
to nrep...@googlegroups.com


On Mon, Sep 3, 2012 at 1:49 PM, Greg R <soapy...@comcast.net> wrote:
Hello-

Has anyone used nrepl with org-babel Clojure?
I use org-babel and I would like to get it running with nrepl instead of slime/swank.

I was wondering if I could get some help modifying these functions to sub nrepl for slime/swank.
Any help would be much appreciated.


Hi Greg,
I took a quick look and was able to an eval from ob-clojure working, so it should be doable.
However there are a few things I need to get merged into master for you to be able to do it.
I will try to get that this evening, and then I can help you with the modifications.

Cheers,
Tim  

Greg R

unread,
Sep 4, 2012, 7:13:27 PM9/4/12
to nrep...@googlegroups.com
Much appreciated!
Greg

Tim King

unread,
Sep 5, 2012, 12:27:48 AM9/5/12
to nrep...@googlegroups.com
On Tue, Sep 4, 2012 at 4:13 PM, Greg R <soapy...@comcast.net> wrote:
Much appreciated!
Greg

 
Hi Greg,
Give this a go:

(declare-function nrepl-send-string-sync "ext:nrepl" (code &optional ns))
(defun org-babel-execute:clojure (body params)
  "Execute a block of Clojure code with Babel."
  (require 'nrepl)
  (with-temp-buffer
    (insert (org-babel-expand-body:clojure body params))
    ((lambda (result)
       (let ((result-params (cdr (assoc :result-params params))))
         (if (or (member "scalar" result-params)
                 (member "verbatim" result-params))
             result
           (condition-case nil (org-babel-script-escape result)
             (error result)))))
     (plist-get (nrepl-send-string-sync
                 (buffer-substring-no-properties (point-min) (point-max))
                 (cdr (assoc :package params)))
                :value))))

It worked for me with the latest code on master.  Let me know if that works for you.

Cheers,
Tim

Greg R

unread,
Sep 5, 2012, 8:02:34 AM9/5/12
to nrep...@googlegroups.com
First quick attempt returns:

Wrong type argument: stringp, nil

in the mini-buffer.
Need to double check my mods to ob-clojure.el.
I changed the name of the compiled elc file, and assume it will load the non-compiled version.

I will try it later today, and I'll post a simple test case if required.
I believe I have the latest and greatest, emacs 24.2, org 7.9, and nrepl 0.1.3 (org and nrepl via elpa).

Regards,
Greg

Tim King

unread,
Sep 5, 2012, 8:05:56 AM9/5/12
to nrep...@googlegroups.com
On Wed, Sep 5, 2012 at 5:02 AM, Greg R <soapy...@comcast.net> wrote:

I will try it later today, and I'll post a simple test case if required.
I believe I have the latest and greatest, emacs 24.2, org 7.9, and nrepl 0.1.3 (org and nrepl via elpa).

 
Hi Greg,
You will need the latest nrepl.el from github (0.1.4-preview).
Cheers,
Tim

Steve Purcell

unread,
Sep 5, 2012, 9:43:29 AM9/5/12
to nrep...@googlegroups.com
On 5 Sep 2012, at 13:05, Tim King <kin...@gmail.com> wrote:
> Hi Greg,
> You will need the latest nrepl.el from github (0.1.4-preview).
>


And there are snapshot packages on Melpa (http://melpa.milkbox.net/).

-Steve

Message has been deleted

Greg R

unread,
Sep 5, 2012, 11:12:31 PM9/5/12
to nrep...@googlegroups.com
I added Melpa to my list of package sources, and the nrepl 0.1.4-preview appeared in the list.
Downloaded and installed the new version of nrepl successfully.

org-babel Clojure is now working with nrepl-jack-in.  I did a quick test drive on a medium sized .org file with
several snippets of Clojure.  I'm using Clojure and Incanter to process some data and write LaTeX and pdf files.
I then export the org file as LaTeX and include the Clojure generated LaTeX files to generate a large document.

Upon initial inspection, everything was output the same as when using lein-swank.
I'll continue to test-drive the set-up and report back with any additional comments.  So far, so good!

Thank you very much for the help,
Greg
Reply all
Reply to author
Forward
0 new messages