* ob-clojure.el alternative using nrepl @ 2013-10-03 15:45 Oleh 2013-10-03 15:46 ` Oleh 2013-10-03 15:54 ` Bastien 0 siblings, 2 replies; 11+ messages in thread From: Oleh @ 2013-10-03 15:45 UTC (permalink / raw) To: org mode [-- Attachment #1: Type: text/plain, Size: 270 bytes --] Hi all, Current method of clojure evaluation is through slime. I couldn't get it to work, when I tried long ago. So I attach one that uses nrepl. Switching between the two should be as easy as using (require 'ob-clojure) or (require 'ob-clojure-nrepl). regards, Oleh [-- Attachment #2: Type: text/html, Size: 438 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 15:45 ob-clojure.el alternative using nrepl Oleh @ 2013-10-03 15:46 ` Oleh 2013-10-03 15:54 ` Bastien 1 sibling, 0 replies; 11+ messages in thread From: Oleh @ 2013-10-03 15:46 UTC (permalink / raw) To: org mode [-- Attachment #1.1: Type: text/plain, Size: 408 bytes --] I guess that I forgot the attachment. Oleh On Thu, Oct 3, 2013 at 5:45 PM, Oleh <ohwoeowho@gmail.com> wrote: > Hi all, > > Current method of clojure evaluation is through slime. > I couldn't get it to work, when I tried long ago. > So I attach one that uses nrepl. > Switching between the two should be as easy as using > > (require 'ob-clojure) > or > (require 'ob-clojure-nrepl). > > regards, > Oleh > [-- Attachment #1.2: Type: text/html, Size: 876 bytes --] [-- Attachment #2: 0001-ob-clojure-nrepl.el-Added-nrepl-alternative-to-ob-cl.patch --] [-- Type: application/octet-stream, Size: 2532 bytes --] From e9e8b9c7b4b1aa9ee132e8a1a9a9d2df1898ba4b Mon Sep 17 00:00:00 2001 From: Oleh Krehel <ohwoeowho@gmail.com> Date: Thu, 3 Oct 2013 17:37:14 +0200 Subject: [PATCH] ob-clojure-nrepl.el: Added nrepl alternative to ob-clojure.el. --- lisp/ob-clojure-nrepl.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lisp/ob-clojure-nrepl.el diff --git a/lisp/ob-clojure-nrepl.el b/lisp/ob-clojure-nrepl.el new file mode 100644 index 0000000..cfae57d --- /dev/null +++ b/lisp/ob-clojure-nrepl.el @@ -0,0 +1,59 @@ +;;; ob-clojure.el --- org-babel functions for clojure evaluation + +;; Copyright (C) 2009-2013 Free Software Foundation, Inc. + +;; Author: Oleh Krehel +;; Keywords: literate programming, reproducible research +;; Homepage: http://orgmode.org + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; support for evaluating clojure code, relies on nrepl for eval + +;;; Requirements: + +;;; - clojure +;;; - clojure-mode +;;; - nrepl + +;;; Best way to get clojure is with https://github.com/technomancy/leiningen +;;; Best way to get nrepl is from MELPA (clojure-mode is a dependency). + +;;; Code: +(require 'ob) +(require 'ob-tangle) + +(defvar org-babel-tangle-lang-exts) +(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj")) + +(defvar org-babel-default-header-args:clojure + '((:results . "value") (:tangle . "yes"))) + +(defun org-babel-execute:clojure (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."))) + +(provide 'ob-clojure-nrepl) + +;;; ob-clojure-nrepl.el ends here -- 1.8.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 15:45 ob-clojure.el alternative using nrepl Oleh 2013-10-03 15:46 ` Oleh @ 2013-10-03 15:54 ` Bastien [not found] ` <CAA01p3rUCr=Q+7QORn_6EEjqqY0SKpKU=0FvRj9-kmDGs=-43w@mail.gmail.com> 1 sibling, 1 reply; 11+ messages in thread From: Bastien @ 2013-10-03 15:54 UTC (permalink / raw) To: Oleh; +Cc: org mode Hi Oleh, Oleh <ohwoeowho@gmail.com> writes: > Current method of clojure evaluation is through slime. > I couldn't get it to work, when I tried long ago. > So I attach one that uses nrepl. > Switching between the two should be as easy as using > > (require 'ob-clojure) > or > (require 'ob-clojure-nrepl). Nice, something needed. I guess we should rather have an option for this in ob-clojure.el, letting users decide whether they want to use nrepl.el or slime, a sensible default being to use nrepl.el. What do you think? -- Bastien ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <CAA01p3rUCr=Q+7QORn_6EEjqqY0SKpKU=0FvRj9-kmDGs=-43w@mail.gmail.com>]
[parent not found: <87hacynx1l.fsf@bzg.ath.cx>]
* Re: ob-clojure.el alternative using nrepl [not found] ` <87hacynx1l.fsf@bzg.ath.cx> @ 2013-10-03 16:27 ` Oleh 2013-10-03 18:06 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Oleh @ 2013-10-03 16:27 UTC (permalink / raw) To: Bastien; +Cc: org mode [-- Attachment #1.1: Type: text/plain, Size: 479 bytes --] Here's an updated patch. I use defalias, is that OK? Oleh On Thu, Oct 3, 2013 at 6:23 PM, Bastien <bzg@gnu.org> wrote: > Hi Oleh, > > Oleh <ohwoeowho@gmail.com> 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 > [-- Attachment #1.2: Type: text/html, Size: 1031 bytes --] [-- Attachment #2: 0001-ob-clojure.el-switch-to-nREPL-as-the-main-method-of-.patch --] [-- Type: application/octet-stream, Size: 2751 bytes --] From ab5c9a8844b4103e40cd4c135f297a7089cd7cdf Mon Sep 17 00:00:00 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 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) -- 1.8.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 16:27 ` Oleh @ 2013-10-03 18:06 ` Eric Schulte 2013-10-03 18:37 ` Oleh 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2013-10-03 18:06 UTC (permalink / raw) To: Oleh; +Cc: Bastien, org mode 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 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 <bzg@gnu.org> wrote: > >> Hi Oleh, >> >> Oleh <ohwoeowho@gmail.com> 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 <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 > 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 18:06 ` Eric Schulte @ 2013-10-03 18:37 ` Oleh 2013-10-03 21:47 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Oleh @ 2013-10-03 18:37 UTC (permalink / raw) To: Eric Schulte; +Cc: Bastien, org mode [-- Attachment #1: Type: text/plain, Size: 4483 bytes --] 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 <schulte.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 > 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 <bzg@gnu.org> wrote: > > > >> Hi Oleh, > >> > >> Oleh <ohwoeowho@gmail.com> 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 <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 > > 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 > [-- Attachment #2: Type: text/html, Size: 6402 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 18:37 ` Oleh @ 2013-10-03 21:47 ` Eric Schulte 2013-10-03 21:56 ` Bastien 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2013-10-03 21:47 UTC (permalink / raw) To: Oleh; +Cc: Bastien, org mode [-- Attachment #1: Type: text/plain, Size: 285 bytes --] Oleh <ohwoeowho@gmail.com> writes: > Hi Eric, > > I can make the changes tomorrow. > Or you can make them now if you like. Please try out the attached patch which may be applied overtop of your patch and let me know if it works? I had to guess at the two nrepl function arguments. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0002-ob-clojure-nrepl-customization-variable.patch --] [-- Type: text/x-diff, Size: 3788 bytes --] From ee6c792ec7657e50524d78d309538e7e58bb2989 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Thu, 3 Oct 2013 13:25:46 -0600 Subject: [PATCH 2/2] 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. --- lisp/ob-clojure.el | 59 +++++++++++++++++++++++++++++------------------------- 1 file 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) -- 1.8.4 [-- Attachment #3: Type: text/plain, Size: 4795 bytes --] > > 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. > I don't see this. With the latest version of Org-mode I'm able to require ob-clojure w/o any problems when starting with no configuration (e.g., "emacs -Q"). Cheers, > > regards, > Oleh > > > On Thu, Oct 3, 2013 at 8:06 PM, Eric Schulte <schulte.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 >> 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 <bzg@gnu.org> wrote: >> > >> >> Hi Oleh, >> >> >> >> Oleh <ohwoeowho@gmail.com> 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 <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 >> > 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 >> -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 21:47 ` Eric Schulte @ 2013-10-03 21:56 ` Bastien 2013-10-03 22:53 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Bastien @ 2013-10-03 21:56 UTC (permalink / raw) To: Eric Schulte; +Cc: org mode, Oleh Hi Eric, Eric Schulte <schulte.eric@gmail.com> writes: > Please try out the attached patch which may be applied overtop of your > patch and let me know if it works? I had to guess at the two nrepl > function arguments. It works fine for nrepl.el, thanks a lot! -- Bastien ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 21:56 ` Bastien @ 2013-10-03 22:53 ` Eric Schulte 2013-10-04 8:26 ` Oleh 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2013-10-03 22:53 UTC (permalink / raw) To: Bastien; +Cc: org mode, Oleh Bastien <bzg@altern.org> writes: > Hi Eric, > > Eric Schulte <schulte.eric@gmail.com> writes: > >> Please try out the attached patch which may be applied overtop of your >> patch and let me know if it works? I had to guess at the two nrepl >> function arguments. > > It works fine for nrepl.el, thanks a lot! Alright, I just pushed this up. Thanks for testing, I haven't used Clojure in a couple of years now (since happily moving on to Common Lisp as my lisp of choice). Thanks to Oleh for the patch! Cheers, -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-03 22:53 ` Eric Schulte @ 2013-10-04 8:26 ` Oleh 2013-10-04 17:05 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Oleh @ 2013-10-04 8:26 UTC (permalink / raw) To: Eric Schulte; +Cc: Bastien, org mode [-- Attachment #1: Type: text/plain, Size: 718 bytes --] Thanks, Eric. Your changes work. Still, I think that it's needed to require ob-tangle. It defines the variable `org-babel-tangle-lang-exts' that ob-clojure wants to modify right at loading. So it's impossible to load ob-clojure unless ob-tangle was already loaded. Just to clarify, this code will work: (setq org-babel-tangle-lang-exts nil) (require 'ob-clojure) whereas (require 'ob-clojure) will not. regards, Oleh > Alright, I just pushed this up. > > Thanks for testing, I haven't used Clojure in a couple of years now > (since happily moving on to Common Lisp as my lisp of choice). > > Thanks to Oleh for the patch! > > Cheers, > > -- > Eric Schulte > https://cs.unm.edu/~eschulte > PGP: 0x614CA05D > [-- Attachment #2: Type: text/html, Size: 1440 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: ob-clojure.el alternative using nrepl 2013-10-04 8:26 ` Oleh @ 2013-10-04 17:05 ` Eric Schulte 0 siblings, 0 replies; 11+ messages in thread From: Eric Schulte @ 2013-10-04 17:05 UTC (permalink / raw) To: Oleh; +Cc: Bastien, org mode Oleh <ohwoeowho@gmail.com> writes: > Thanks, Eric. > > Your changes work. > Great, thanks for the patch. > > Still, I think that it's needed to require ob-tangle. > It defines the variable `org-babel-tangle-lang-exts' that ob-clojure > wants to modify right at loading. So it's impossible to load ob-clojure > unless ob-tangle was already loaded. > > Just to clarify, this code will work: > > (setq org-babel-tangle-lang-exts nil) > (require 'ob-clojure) > > whereas > > (require 'ob-clojure) > > will not. > I think this must be particular to your system. The (defvar org-babel-tangle-lang-exts) form in ob-clojure.el should take care of this problem, and indeed does for me. $ emacs --batch --eval "(progn (add-to-list 'load-path \"~/src/org-mode/lisp\") (require 'org) (require 'ob-clojure) (message \"success\"))" success Cheers, > > regards, > Oleh > > >> Alright, I just pushed this up. >> >> Thanks for testing, I haven't used Clojure in a couple of years now >> (since happily moving on to Common Lisp as my lisp of choice). >> >> Thanks to Oleh for the patch! >> >> Cheers, >> >> -- >> Eric Schulte >> https://cs.unm.edu/~eschulte >> PGP: 0x614CA05D >> -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-10-04 17:06 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-10-03 15:45 ob-clojure.el alternative using nrepl Oleh 2013-10-03 15:46 ` Oleh 2013-10-03 15:54 ` Bastien [not found] ` <CAA01p3rUCr=Q+7QORn_6EEjqqY0SKpKU=0FvRj9-kmDGs=-43w@mail.gmail.com> [not found] ` <87hacynx1l.fsf@bzg.ath.cx> 2013-10-03 16:27 ` Oleh 2013-10-03 18:06 ` Eric Schulte 2013-10-03 18:37 ` Oleh 2013-10-03 21:47 ` Eric Schulte 2013-10-03 21:56 ` Bastien 2013-10-03 22:53 ` Eric Schulte 2013-10-04 8:26 ` Oleh 2013-10-04 17:05 ` Eric Schulte
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.