emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Clojure Code Block Results not Tabularized


From: Eric Schulte
Subject: Re: [O] Clojure Code Block Results not Tabularized
Date: Wed, 29 Jan 2014 08:02:19 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Soapy Smith <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]