emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Soapy Smith <soapy-smith@comcast.net>
Cc: emacs-orgmode@gnu.org, Christian Moe <mail@christianmoe.com>
Subject: Re: Clojure Code Block Results not Tabularized
Date: Wed, 29 Jan 2014 08:02:19 -0700	[thread overview]
Message-ID: <87d2ja4yro.fsf@gmail.com> (raw)
In-Reply-To: <1391000780.2272.18.camel@raven-CM5571> (Soapy Smith's message of "Wed, 29 Jan 2014 08:06:20 -0500")

Soapy Smith <soapy-smith@comcast.net> writes:

> Yes, I agree the Clojure behavior is not quite correct.  But all the
> functionality is there if both the old and new are combined.  I think
> only a rearrangement of existing code is required.
>

Try evaluating the following and see how it works.  This simply copies
the results handling from the slime backend to the cider backend (which
currently does not appear to have any results handling).  While you're
at it the nrepl results handling looks broken to me as well.  Maybe
Bastien (who I believe wrote or committed this code) can help.

(defun org-babel-execute:clojure (body params)
  "Execute a block of Clojure code with Babel."
  (let ((expanded (org-babel-expand-body:clojure body params)))
    (case org-babel-clojure-backend
      (cider
       (require 'cider)
       (let ((result
	      (or (nth 1 (nrepl-send-string-sync
			  expanded
			  (cider-current-ns)
			  (nrepl-current-tooling-session)))
		  (error "nREPL not connected!  Use M-x cider-jack-in RET"))))
	 (org-babel-result-cond (cdr (assoc :result-params params))
	   result
	   (condition-case nil (org-babel-script-escape result)
	     (error result)))))
      (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 RET")))
      (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)))))))))

I don't have clojure installed locally and can't test.

Best,

>
> I like the idea of comparing to the behavior of Python code blocks.
> I've got a Coursera class coming up which will use Python, so I need to
> get it set it up here.
>
> Thank you for the assistance!
> Greg
>
> On Wed, 2014-01-29 at 13:58 +0100, Christian Moe wrote:
>> Soapy Smith writes:
>> 
>> > Christian, could you try :results table with Python and reply back with
>> > the #+RESULTS:?
>> 
>> Same as the default, i.e. a table, as expected.
>> #+RESULTS:
>> | 1 | 2 | 3 |
>> 
>> The Babel/Clojure behavior you report does seem buggy. 
>> 
>> I'm afraid I can't be of further help, but hopefully others will pick up
>> on this.
>> 
>> Yours,
>> Christian
>
>
>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

  reply	other threads:[~2014-01-29 15:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 13:41 How to use ox-bibtex o.castillo.felisola
2014-01-26 18:02 ` Eric Schulte
2014-01-26 19:37   ` o.castillo.felisola
2014-01-27 13:52     ` o.castillo.felisola
2014-01-27 14:36       ` Eric Schulte
2014-01-28  8:32         ` Rainer M Krug
2014-01-28  9:04           ` Christian Moe
2014-01-28 10:08             ` Rainer M Krug
2014-01-28 12:38           ` Rainer M Krug
2014-01-28 15:19             ` o.castillo.felisola
2014-01-29  2:16               ` Eric Schulte
2014-01-29 14:16                 ` o.castillo.felisola
2014-01-29 14:46                   ` Nick Dokos
2014-01-30 10:02                     ` Ahmadou Dicko
2014-01-28 12:33         ` o.castillo.felisola
2014-01-28 12:01       ` Rainer M Krug
2014-01-28 13:23 ` Clojure Code Block Results not Tabularized Soapy Smith
2014-01-29  7:57   ` Christian Moe
2014-01-29 12:36     ` Soapy Smith
2014-01-29 12:58       ` Christian Moe
2014-01-29 13:06         ` Soapy Smith
2014-01-29 15:02           ` Eric Schulte [this message]
2014-01-29 15:28             ` Bastien
2014-01-29 23:40               ` Phill Wolf
2014-01-30 11:11   ` Bastien
2014-01-30 13:46     ` Soapy Smith
2014-01-31  1:58     ` Soapy Smith
2014-01-31  9:11       ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d2ja4yro.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@christianmoe.com \
    --cc=soapy-smith@comcast.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).