From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleh Subject: Re: ob-clojure.el alternative using nrepl Date: Thu, 3 Oct 2013 20:37:01 +0200 Message-ID: References: <87mwmqpcyd.fsf@bzg.ath.cx> <87hacynx1l.fsf@bzg.ath.cx> <8761temdp1.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=485b3970d64ebfb24d04e7da78e4 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRnlp-0002SL-BR for emacs-orgmode@gnu.org; Thu, 03 Oct 2013 14:37:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRnln-0006Rz-4p for emacs-orgmode@gnu.org; Thu, 03 Oct 2013 14:37:05 -0400 In-Reply-To: <8761temdp1.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: Bastien , org mode --485b3970d64ebfb24d04e7da78e4 Content-Type: text/plain; charset=ISO-8859-1 Hi Eric, I can make the changes tomorrow. Or you can make them now if you like. I required ob-tangle because it's a pre-requisite for ob-clojure: an error is thrown if I try to load ob-clojure before ob-tangle. So it makes sense to me to require it. regards, Oleh On Thu, Oct 3, 2013 at 8:06 PM, Eric Schulte wrote: > Thanks for this update. > > Oleh writes: > > > Here's an updated patch. > > I use defalias, is that OK? > > > > Two changes. > > 1. instead of customization through a defalias, use defcustom and a > variable which determines which function (eval-slime or eval-nrepl) > is called. > > 2. ob-*.el files should not require ob-tangle. > > If you prefer not to make these changes I can apply your patch, and then > make the required changes myself over-top. > > Best, > > > > > Oleh > > > > > > On Thu, Oct 3, 2013 at 6:23 PM, Bastien wrote: > > > >> Hi Oleh, > >> > >> Oleh writes: > >> > >> > Should I rather put the code in ob-clojure.el with something like > >> > (defcustom ob-clojure-method nrepl)? > >> > >> Yes, I think it's better. Maybe > >> > >> (defcustom ob-clojure-repl 'nrepl) > >> > >> Let's discuss this on the list so that others can chime in. > >> > >> Thanks for bringing this up! > >> > >> -- > >> Bastien > >> > > > > From ab5c9a8844b4103e40cd4c135f297a7089cd7cdf Mon Sep 17 00:00:00 2001 > > From: Oleh Krehel > > Date: Thu, 3 Oct 2013 18:23:16 +0200 > > Subject: [PATCH] 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) > > --- > > lisp/ob-clojure.el | 34 ++++++++++++++++++++++++++-------- > > 1 file 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) > > -- > Eric Schulte > https://cs.unm.edu/~eschulte > PGP: 0x614CA05D > --485b3970d64ebfb24d04e7da78e4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Eric,

I can make the changes tomorro= w.
Or you can make them now if you like.
I required ob-= tangle because it's a pre-requisite for ob-clojure:
an error = is thrown if I try to load ob-clojure before ob-tangle.
So it makes sense to me to require it.

regard= s,
Oleh


On Thu, Oct 3, 2013 at 8:06 PM, Eric Schulte <schult= e.eric@gmail.com> wrote:
Thanks for this update.

Oleh <ohwoeowho@gmail.com>= writes:

> Here's an updated patch.
> I use defalias, is that OK?
>

Two changes.

1. instead of customization through a defalias, use defcustom and a
=A0 =A0variable which determines which function (eval-slime or eval-nrepl)<= br> =A0 =A0is called.

2. ob-*.el files should not require ob-tangle.

If you prefer not to make these changes I can apply your patch, and then make the required changes myself over-top.

Best,

>
> Oleh
>
>
> On Thu, Oct 3, 2013 at 6:23 PM, Bastien <bzg@gnu.org> wrote:
>
>> Hi Oleh,
>>
>> Oleh <ohwoeowho@gmail.co= m> writes:
>>
>> > Should I rather put the code in ob-clojure.el with something = like
>> > (defcustom ob-clojure-method nrepl)?
>>
>> Yes, I think it's better. =A0Maybe
>>
>> (defcustom ob-clojure-repl 'nrepl)
>>
>> Let's discuss this on the list so that others can chime in. >>
>> Thanks for bringing this up!
>>
>> --
>> =A0Bastien
>>
>
> From ab5c9a8844b4103e40cd4c135f297a7089cd7cdf Mon Sep 17 00:00:0= 0 2001
> From: Oleh Krehel <ohwoeowho= @gmail.com>
> Date: Thu, 3 Oct 2013 18:23:16 +0200
> Subject: [PATCH] ob-clojure.el: switch to nREPL as the main method of<= br> > =A0evaluating Clojure.
>
> Get the old behavior with:
> (defalias 'org-babel-execute:clojure 'org-babel--execute-cloju= re-slime)
> ---
> =A0lisp/ob-clojure.el | 34 ++++++++++++++++++++++++++--------
> =A01 file 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 @@
>
> =A0;; Copyright (C) 2009-2013 Free Software Foundation, Inc.
>
> -;; Author: Joel Boehland
> -;; =A0 Eric Schulte
> +;; Author: Joel Boehland, Eric Schulte, Oleh Krehel
> +;;
> =A0;; Keywords: literate programming, reproducible research
> =A0;; Homepage: http:= //orgmode.org
>
> @@ -24,20 +24,26 @@
>
> =A0;;; 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
>
> =A0;;; Requirements:
>
> =A0;;; - clojure (at least 1.2.0)
> =A0;;; - clojure-mode
> -;;; - slime
> +;;; - either slime or nrepl
>
> -;;; By far, the best way to install these components is by following<= br> > -;;; the directions as set out by Phil Hagelberg (Technomancy) on the<= br> > -;;; 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 (Technomanc= y)
> +;;; 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).
>
> =A0;;; Code:
> =A0(require 'ob)
> +(require 'ob-tangle)
>
> =A0(declare-function slime-eval "ext:slime" (sexp &optio= nal package))
>
> @@ -72,7 +78,7 @@
> =A0 =A0 =A0 =A0 =A0(format "(clojure.core/with-out-str %s)" = body))
> =A0 =A0 =A0 =A0 (t body))))
>
> -(defun org-babel-execute:clojure (body params)
> +(defun org-babel--execute-clojure-slime (body params)
> =A0 =A0"Execute a block of Clojure code with Babel."
> =A0 =A0(require 'slime)
> =A0 =A0(with-temp-buffer
> @@ -88,6 +94,18 @@
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 ,(buffer-substring-no-properties (point-mi= n) (point-max)))
> =A0 =A0 =A0 =A0(cdr (assoc :package params))))))
>
> +(defun org-babel--execute-clojure-nrepl (body params)
> + =A0"Execute a block of Clojure code with Babel and nREPL."=
> + =A0(require 'nrepl)
> + =A0(if (nrepl-current-connection-buffer)
> + =A0 =A0 =A0(let* ((result (nrepl-eval body))
> + =A0 =A0 =A0 =A0 =A0 =A0 (s (plist-get result :stdout))
> + =A0 =A0 =A0 =A0 =A0 =A0 (r (plist-get result :value)))
> + =A0 =A0 =A0 =A0(if s (concat s "\n" r) r))
> + =A0 =A0(error "nREPL not connected! Use M-x nrepl-jack-in."= ;)))
> +
> +(defalias 'org-babel-execute:clojure 'org-babel--execute-cloj= ure-nrepl)
> +
> =A0(provide 'ob-clojure)

--
Eric Schulte
https://cs.unm.e= du/~eschulte
PGP: 0x614CA05D

--485b3970d64ebfb24d04e7da78e4--