all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ob-clojure evaluate error when Org-mode buffer has ns clojure code
@ 2017-06-16 15:36 numbchild
  2017-06-17  1:46 ` Tim Cross
  0 siblings, 1 reply; 9+ messages in thread
From: numbchild @ 2017-06-16 15:36 UTC (permalink / raw)
  To: Org-mode

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

When Org-mode buffer like this:

#+BEGIN_SRC clojure
(ns my.kk
  (:require '[incanter.core :as kk]))
#+END_SRC

#+BEGIN_SRC clojure
(print "hi")
(def kkkk "hello")
#+END_SRC

#+RESULTS:

When I have `(ns ..)` namespace clojure code in buffer, the second `(print
..)` clojure result nothing. But when I remove the first src block, the
`(print ..)` clojure src block works fine.

I'm using Org-mode version from `master` with `use-package` like this:

(use-package org
  :load-path "~/Code/Emacs/org-mode/lisp/"
  :pin manual
  :mode (("\\.org$" . org-mode))
  :config
  (use-package org-plus-contrib
    :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
    :pin manual)
  )


[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

[-- Attachment #2: Type: text/html, Size: 2954 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-16 15:36 ob-clojure evaluate error when Org-mode buffer has ns clojure code numbchild
@ 2017-06-17  1:46 ` Tim Cross
  2017-06-17 12:57   ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: Tim Cross @ 2017-06-17  1:46 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode


My guess is that cider is not finding the incanter package in the
classpath when the first block attempts to evaluate. Another issue is
that your not using any session options, so your two blocks will be
evaluated in separate environments - not a real problem with your
current example, but will be an issue if you expect to access incanter
functions from separate babel blocks.

There are a number of working parts which all need to be lined up
correctly before babel clojure support will work correctly. Getting
things to work when your just using core clojure functions is fairly
trivial, but getting it to work when you have to pull in other
dependencies can be a little tricky.

You might find this article useful to get started

http://fgiasson.com/blog/index.php/2016/06/21/optimal-emacs-settings-for-org-mode-for-literate-programming/

I also notice you have not set the org-babel-clojure-backend, which you
need to do. My recommendation would be to do the following

1. Create a leinegen project to experiment with i.e.
lein new app my-kk

2. Make sure you can edit and evaluate clojure just using clojure-mode
and cider in emacs

3. Add the incanter package to your project.clj dependencies key

4. Modify core.clj (using clojure-mode) to include the code in your
clojure blocks and run with cider to make sure they work as expected.

5. Create the org file you want to experiment with in the root of your
project. This should ensure that when you try to evaluate clojure
blocks, the cider backend will be loaded with the dependencies in the
project.clj file.

6. Copy the code in your core.clj file into ONE babel src block and see
if you can get it to evaluate correctly. Experiment with the block
configuration options like :output etc. 

7. Break the code up into different blocks and experiment with block
options, especially session options.

Once you get to that point, you should be across the various moving
parts with sufficient understanding to then look at how you can tweak
things to get exactly the behaviour and workflow you want. 

HTH

Tim

numbchild@gmail.com writes:

> When Org-mode buffer like this:
>
> #+BEGIN_SRC clojure
> (ns my.kk
>   (:require '[incanter.core :as kk]))
> #+END_SRC
>
> #+BEGIN_SRC clojure
> (print "hi")
> (def kkkk "hello")
> #+END_SRC
>
> #+RESULTS:
>
> When I have `(ns ..)` namespace clojure code in buffer, the second `(print
> ..)` clojure result nothing. But when I remove the first src block, the
> `(print ..)` clojure src block works fine.
>
> I'm using Org-mode version from `master` with `use-package` like this:
>
> (use-package org
>   :load-path "~/Code/Emacs/org-mode/lisp/"
>   :pin manual
>   :mode (("\\.org$" . org-mode))
>   :config
>   (use-package org-plus-contrib
>     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
>     :pin manual)
>   )
>
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/


-- 
Tim Cross

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-17  1:46 ` Tim Cross
@ 2017-06-17 12:57   ` numbchild
  2017-06-17 13:26     ` numbchild
  2017-06-18  1:10     ` Tim Cross
  0 siblings, 2 replies; 9+ messages in thread
From: numbchild @ 2017-06-17 12:57 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 10478 bytes --]

I did configure `ob-clojure` with the following settings:

```elisp
(require 'ob-clojure)

;; use CIDER as the Clojure execution backend
(setq org-babel-clojure-backend 'cider)

;; Useful keybindings when using Clojure from Org
;; (org-defkey org-mode-map (kbd "C-x C-e") 'cider-eval-last-sexp)
;; (org-defkey org-mode-map (kbd "C-c C-d") 'cider-doc)

;; No timeout when executing calls on Cider via nrepl
;; (setq org-babel-clojure-sync-nrepl-timeout nil)

;; let `ob-clojure' babel src blocks allow evaluation.
(add-to-list 'org-babel-default-header-args:clojure
             '(:eval . "yes"))
(add-to-list 'org-babel-default-header-args:clojure
             '(:results . "output"))
;; (add-to-list 'org-babel-default-header-args:clojure
;;              '(:show-process . t))
```

I start CIDER REPL session with `cider-jack-in` without project in Emacs.

I changed namespace to `user` in src blocks like this:

```org
#+BEGIN_SRC clojure
(ns user
  (:require '[incanter.core :as kk]))
#+END_SRC

#+RESULTS:

#+BEGIN_SRC clojure :session :results output
(print "hi")
(def kkkk "hello")
#+END_SRC

#+RESULTS:
: hi
```

Then it works.

Seems you're right, might my first src block can't work correctly. That
caused second src block evaluation failed.

But I require `incanter` works, I have `incanter` in Leiningen dependencies.
```clojure
(require '[incanter.core :as kk])
```

But include `incanter` in namespace failed:
```clojure
(ns user
  (:require '[incanter.core :as kk]))
```
with the following error.
```
  Show: Clojure Java REPL Tooling Duplicates All  (29 frames hidden)

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling Code/learning/Emacs/Org-mode/ob-clojure.org at (1:1)

                  core.clj: 5771  clojure.core/throw-if
                  core.clj: 5835  clojure.core/load-lib
                  core.clj: 5832  clojure.core/load-lib
               RestFn.java:  142  clojure.lang.RestFn/applyTo
                  core.clj:  659  clojure.core/apply
                  core.clj: 5893  clojure.core/load-libs
                  core.clj: 5873  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  659  clojure.core/apply
                  core.clj: 5911  clojure.core/require
                  core.clj: 5911  clojure.core/require
               RestFn.java:  408  clojure.lang.RestFn/invoke
                      REPL:    1  user/eval46259/loading--auto--
                      REPL:    1  user/eval46259
                      REPL:    1  user/eval46259
             Compiler.java: 6977  clojure.lang.Compiler/eval
             Compiler.java: 6966  clojure.lang.Compiler/eval
             Compiler.java: 6940  clojure.lang.Compiler/eval
                  core.clj: 3187  clojure.core/eval
                  core.clj: 3183  clojure.core/eval
                  main.clj:  242  clojure.main/repl/read-eval-print/fn
                  main.clj:  242  clojure.main/repl/read-eval-print
                  main.clj:  260  clojure.main/repl/fn
                  main.clj:  260  clojure.main/repl
                  main.clj:  176  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  657  clojure.core/apply
                  core.clj: 1963  clojure.core/with-bindings*
                  core.clj: 1963  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222
 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190
 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1142
 java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  617
 java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  745  java.lang.Thread/run

1. Caused by java.lang.Exception
   Found lib name 'incanter.stats' containing period with prefix 'quote'.
lib
   names inside prefix lists must not contain periods

                  core.clj:  659  clojure.core/apply
                  core.clj: 5893  clojure.core/load-libs
                  core.clj: 5873  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  659  clojure.core/apply
                  core.clj: 5911  clojure.core/require
                  core.clj: 5911  clojure.core/require
               RestFn.java:  408  clojure.lang.RestFn/invoke
                      REPL:    1  user/eval46259/loading--auto--
                      REPL:    1  user/eval46259
                      REPL:    1  user/eval46259
             Compiler.java: 6977  clojure.lang.Compiler/eval
             Compiler.java: 6966  clojure.lang.Compiler/eval
             Compiler.java: 6940  clojure.lang.Compiler/eval
                  core.clj: 3187  clojure.core/eval
                  core.clj: 3183  clojure.core/eval
                  main.clj:  242  clojure.main/repl/read-eval-print/fn
                  main.clj:  242  clojure.main/repl/read-eval-print
                  main.clj:  260  clojure.main/repl/fn
                  main.clj:  260  clojure.main/repl
                  main.clj:  176  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  657  clojure.core/apply
                  core.clj: 1963  clojure.core/with-bindings*
                  core.clj: 1963  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55
 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222
 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190
 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1142
 java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  617
 java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  745  java.lang.Thread/run
```


[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sat, Jun 17, 2017 at 9:46 AM, Tim Cross <theophilusx@gmail.com> wrote:

>
> My guess is that cider is not finding the incanter package in the
> classpath when the first block attempts to evaluate. Another issue is
> that your not using any session options, so your two blocks will be
> evaluated in separate environments - not a real problem with your
> current example, but will be an issue if you expect to access incanter
> functions from separate babel blocks.
>
> There are a number of working parts which all need to be lined up
> correctly before babel clojure support will work correctly. Getting
> things to work when your just using core clojure functions is fairly
> trivial, but getting it to work when you have to pull in other
> dependencies can be a little tricky.
>
> You might find this article useful to get started
>
> http://fgiasson.com/blog/index.php/2016/06/21/optimal-
> emacs-settings-for-org-mode-for-literate-programming/
>
> I also notice you have not set the org-babel-clojure-backend, which you
> need to do. My recommendation would be to do the following
>
> 1. Create a leinegen project to experiment with i.e.
> lein new app my-kk
>
> 2. Make sure you can edit and evaluate clojure just using clojure-mode
> and cider in emacs
>
> 3. Add the incanter package to your project.clj dependencies key
>
> 4. Modify core.clj (using clojure-mode) to include the code in your
> clojure blocks and run with cider to make sure they work as expected.
>
> 5. Create the org file you want to experiment with in the root of your
> project. This should ensure that when you try to evaluate clojure
> blocks, the cider backend will be loaded with the dependencies in the
> project.clj file.
>
> 6. Copy the code in your core.clj file into ONE babel src block and see
> if you can get it to evaluate correctly. Experiment with the block
> configuration options like :output etc.
>
> 7. Break the code up into different blocks and experiment with block
> options, especially session options.
>
> Once you get to that point, you should be across the various moving
> parts with sufficient understanding to then look at how you can tweak
> things to get exactly the behaviour and workflow you want.
>
> HTH
>
> Tim
>
> numbchild@gmail.com writes:
>
> > When Org-mode buffer like this:
> >
> > #+BEGIN_SRC clojure
> > (ns my.kk
> >   (:require '[incanter.core :as kk]))
> > #+END_SRC
> >
> > #+BEGIN_SRC clojure
> > (print "hi")
> > (def kkkk "hello")
> > #+END_SRC
> >
> > #+RESULTS:
> >
> > When I have `(ns ..)` namespace clojure code in buffer, the second
> `(print
> > ..)` clojure result nothing. But when I remove the first src block, the
> > `(print ..)` clojure src block works fine.
> >
> > I'm using Org-mode version from `master` with `use-package` like this:
> >
> > (use-package org
> >   :load-path "~/Code/Emacs/org-mode/lisp/"
> >   :pin manual
> >   :mode (("\\.org$" . org-mode))
> >   :config
> >   (use-package org-plus-contrib
> >     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
> >     :pin manual)
> >   )
> >
> >
> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> > Blog: http://stardiviner.github.io/
>
>
> --
> Tim Cross
>

[-- Attachment #2: Type: text/html, Size: 22129 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-17 12:57   ` numbchild
@ 2017-06-17 13:26     ` numbchild
  2017-06-18  1:10     ` Tim Cross
  1 sibling, 0 replies; 9+ messages in thread
From: numbchild @ 2017-06-17 13:26 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 12610 bytes --]

After a new evaluation. I found
```org
#+BEGIN_SRC clojure
(ns user
  (:require '[incanter.core :as mm]))
#+END_SRC

#+RESULTS:
: class clojure.lang.Compiler$CompilerExceptionclass
clojure.lang.Compiler$CompilerExceptionCompilerException
java.lang.Exception: Found lib name 'incanter.core' containing period with
prefix 'quote'.  lib names inside prefix lists must not contain periods,
compiling:(/home/stardiviner/Code/learning/Emacs/Org-mode/ob-clojure.org:1
:1)

#+BEGIN_SRC clojure :session :results output
(print "hi")
(def kkkk "hello")
#+END_SRC

#+RESULTS:
: hi
```

Both two src blocks works. Because the first src block Clojure namespace
`(ns user ..)` is same with CIDER REPL default namespace `user`. So it
works.

But when I tried add header argument `:eval no` on first src block like
this:

```org
#+BEGIN_SRC clojure :session :eval no
(ns user.kk
  (:require '[incanter.core :as mm]))
#+END_SRC

#+RESULTS:

#+BEGIN_SRC clojure :session :results output
(print "hi")
(def kkkk "hello")
#+END_SRC

#+RESULTS:
```

The second src block failed again. So I think `ob-clojure` will try to
evaluate the first src block even I added header argument `:eval no`. So
`ob-clojure.el` does not respect header argument `:eval no`. But I think
might because `:eval no` is not work for this purpose. I did can't evaluate
by pressing `[C-c C-c]` on first block.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sat, Jun 17, 2017 at 8:57 PM, numbchild@gmail.com <numbchild@gmail.com>
wrote:

> I did configure `ob-clojure` with the following settings:
>
> ```elisp
> (require 'ob-clojure)
>
> ;; use CIDER as the Clojure execution backend
> (setq org-babel-clojure-backend 'cider)
>
> ;; Useful keybindings when using Clojure from Org
> ;; (org-defkey org-mode-map (kbd "C-x C-e") 'cider-eval-last-sexp)
> ;; (org-defkey org-mode-map (kbd "C-c C-d") 'cider-doc)
>
> ;; No timeout when executing calls on Cider via nrepl
> ;; (setq org-babel-clojure-sync-nrepl-timeout nil)
>
> ;; let `ob-clojure' babel src blocks allow evaluation.
> (add-to-list 'org-babel-default-header-args:clojure
>              '(:eval . "yes"))
> (add-to-list 'org-babel-default-header-args:clojure
>              '(:results . "output"))
> ;; (add-to-list 'org-babel-default-header-args:clojure
> ;;              '(:show-process . t))
> ```
>
> I start CIDER REPL session with `cider-jack-in` without project in Emacs.
>
> I changed namespace to `user` in src blocks like this:
>
> ```org
> #+BEGIN_SRC clojure
> (ns user
>   (:require '[incanter.core :as kk]))
> #+END_SRC
>
> #+RESULTS:
>
> #+BEGIN_SRC clojure :session :results output
> (print "hi")
> (def kkkk "hello")
> #+END_SRC
>
> #+RESULTS:
> : hi
> ```
>
> Then it works.
>
> Seems you're right, might my first src block can't work correctly. That
> caused second src block evaluation failed.
>
> But I require `incanter` works, I have `incanter` in Leiningen
> dependencies.
> ```clojure
> (require '[incanter.core :as kk])
> ```
>
> But include `incanter` in namespace failed:
> ```clojure
> (ns user
>   (:require '[incanter.core :as kk]))
> ```
> with the following error.
> ```
>   Show: Clojure Java REPL Tooling Duplicates All  (29 frames hidden)
>
> 2. Unhandled clojure.lang.Compiler$CompilerException
>    Error compiling Code/learning/Emacs/Org-mode/ob-clojure.org at (1:1)
>
>                   core.clj: 5771  clojure.core/throw-if
>                   core.clj: 5835  clojure.core/load-lib
>                   core.clj: 5832  clojure.core/load-lib
>                RestFn.java:  142  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5893  clojure.core/load-libs
>                   core.clj: 5873  clojure.core/load-libs
>                RestFn.java:  137  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5911  clojure.core/require
>                   core.clj: 5911  clojure.core/require
>                RestFn.java:  408  clojure.lang.RestFn/invoke
>                       REPL:    1  user/eval46259/loading--auto--
>                       REPL:    1  user/eval46259
>                       REPL:    1  user/eval46259
>              Compiler.java: 6977  clojure.lang.Compiler/eval
>              Compiler.java: 6966  clojure.lang.Compiler/eval
>              Compiler.java: 6940  clojure.lang.Compiler/eval
>                   core.clj: 3187  clojure.core/eval
>                   core.clj: 3183  clojure.core/eval
>                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>                   main.clj:  242  clojure.main/repl/read-eval-print
>                   main.clj:  260  clojure.main/repl/fn
>                   main.clj:  260  clojure.main/repl
>                   main.clj:  176  clojure.main/repl
>                RestFn.java: 1523  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   87  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate/fn
>                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>                   AFn.java:  144  clojure.lang.AFn/applyTo
>                   core.clj:  657  clojure.core/apply
>                   core.clj: 1963  clojure.core/with-bindings*
>                   core.clj: 1963  clojure.core/with-bindings*
>                RestFn.java:  425  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   85  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:   55  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:  222  clojure.tools.nrepl.
> middleware.interruptible-eval/interruptible-eval/fn/fn
>     interruptible_eval.clj:  190  clojure.tools.nrepl.
> middleware.interruptible-eval/run-next/fn
>                   AFn.java:   22  clojure.lang.AFn/run
>    ThreadPoolExecutor.java: 1142  java.util.concurrent.
> ThreadPoolExecutor/runWorker
>    ThreadPoolExecutor.java:  617  java.util.concurrent.
> ThreadPoolExecutor$Worker/run
>                Thread.java:  745  java.lang.Thread/run
>
> 1. Caused by java.lang.Exception
>    Found lib name 'incanter.stats' containing period with prefix 'quote'.
> lib
>    names inside prefix lists must not contain periods
>
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5893  clojure.core/load-libs
>                   core.clj: 5873  clojure.core/load-libs
>                RestFn.java:  137  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5911  clojure.core/require
>                   core.clj: 5911  clojure.core/require
>                RestFn.java:  408  clojure.lang.RestFn/invoke
>                       REPL:    1  user/eval46259/loading--auto--
>                       REPL:    1  user/eval46259
>                       REPL:    1  user/eval46259
>              Compiler.java: 6977  clojure.lang.Compiler/eval
>              Compiler.java: 6966  clojure.lang.Compiler/eval
>              Compiler.java: 6940  clojure.lang.Compiler/eval
>                   core.clj: 3187  clojure.core/eval
>                   core.clj: 3183  clojure.core/eval
>                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>                   main.clj:  242  clojure.main/repl/read-eval-print
>                   main.clj:  260  clojure.main/repl/fn
>                   main.clj:  260  clojure.main/repl
>                   main.clj:  176  clojure.main/repl
>                RestFn.java: 1523  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   87  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate/fn
>                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>                   AFn.java:  144  clojure.lang.AFn/applyTo
>                   core.clj:  657  clojure.core/apply
>                   core.clj: 1963  clojure.core/with-bindings*
>                   core.clj: 1963  clojure.core/with-bindings*
>                RestFn.java:  425  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   85  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:   55  clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:  222  clojure.tools.nrepl.
> middleware.interruptible-eval/interruptible-eval/fn/fn
>     interruptible_eval.clj:  190  clojure.tools.nrepl.
> middleware.interruptible-eval/run-next/fn
>                   AFn.java:   22  clojure.lang.AFn/run
>    ThreadPoolExecutor.java: 1142  java.util.concurrent.
> ThreadPoolExecutor/runWorker
>    ThreadPoolExecutor.java:  617  java.util.concurrent.
> ThreadPoolExecutor$Worker/run
>                Thread.java:  745  java.lang.Thread/run
> ```
>
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/
>
> On Sat, Jun 17, 2017 at 9:46 AM, Tim Cross <theophilusx@gmail.com> wrote:
>
>>
>> My guess is that cider is not finding the incanter package in the
>> classpath when the first block attempts to evaluate. Another issue is
>> that your not using any session options, so your two blocks will be
>> evaluated in separate environments - not a real problem with your
>> current example, but will be an issue if you expect to access incanter
>> functions from separate babel blocks.
>>
>> There are a number of working parts which all need to be lined up
>> correctly before babel clojure support will work correctly. Getting
>> things to work when your just using core clojure functions is fairly
>> trivial, but getting it to work when you have to pull in other
>> dependencies can be a little tricky.
>>
>> You might find this article useful to get started
>>
>> http://fgiasson.com/blog/index.php/2016/06/21/optimal-emacs-
>> settings-for-org-mode-for-literate-programming/
>>
>> I also notice you have not set the org-babel-clojure-backend, which you
>> need to do. My recommendation would be to do the following
>>
>> 1. Create a leinegen project to experiment with i.e.
>> lein new app my-kk
>>
>> 2. Make sure you can edit and evaluate clojure just using clojure-mode
>> and cider in emacs
>>
>> 3. Add the incanter package to your project.clj dependencies key
>>
>> 4. Modify core.clj (using clojure-mode) to include the code in your
>> clojure blocks and run with cider to make sure they work as expected.
>>
>> 5. Create the org file you want to experiment with in the root of your
>> project. This should ensure that when you try to evaluate clojure
>> blocks, the cider backend will be loaded with the dependencies in the
>> project.clj file.
>>
>> 6. Copy the code in your core.clj file into ONE babel src block and see
>> if you can get it to evaluate correctly. Experiment with the block
>> configuration options like :output etc.
>>
>> 7. Break the code up into different blocks and experiment with block
>> options, especially session options.
>>
>> Once you get to that point, you should be across the various moving
>> parts with sufficient understanding to then look at how you can tweak
>> things to get exactly the behaviour and workflow you want.
>>
>> HTH
>>
>> Tim
>>
>> numbchild@gmail.com writes:
>>
>> > When Org-mode buffer like this:
>> >
>> > #+BEGIN_SRC clojure
>> > (ns my.kk
>> >   (:require '[incanter.core :as kk]))
>> > #+END_SRC
>> >
>> > #+BEGIN_SRC clojure
>> > (print "hi")
>> > (def kkkk "hello")
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> >
>> > When I have `(ns ..)` namespace clojure code in buffer, the second
>> `(print
>> > ..)` clojure result nothing. But when I remove the first src block, the
>> > `(print ..)` clojure src block works fine.
>> >
>> > I'm using Org-mode version from `master` with `use-package` like this:
>> >
>> > (use-package org
>> >   :load-path "~/Code/Emacs/org-mode/lisp/"
>> >   :pin manual
>> >   :mode (("\\.org$" . org-mode))
>> >   :config
>> >   (use-package org-plus-contrib
>> >     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
>> >     :pin manual)
>> >   )
>> >
>> >
>> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
>> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
>> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
>> > Blog: http://stardiviner.github.io/
>>
>>
>> --
>> Tim Cross
>>
>
>

[-- Attachment #2: Type: text/html, Size: 27706 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-17 12:57   ` numbchild
  2017-06-17 13:26     ` numbchild
@ 2017-06-18  1:10     ` Tim Cross
  2017-06-18  5:48       ` numbchild
  1 sibling, 1 reply; 9+ messages in thread
From: Tim Cross @ 2017-06-18  1:10 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode


It looks like you have a combination of both clojure errors and possibly
org babel errors. You need to sort out the clojure errors before you can
verify there are any problems with org babel clojure support.

You mention that

> I start CIDER REPL session with `cider-jack-in` without project in
> Emacs.

but then you say

> But I require `incanter` works, I have `incanter` in Leiningen
> dependencies.

However, if you don't have a project, then you don't have a project.clj
file and if you don't have a project.clj file, you don't have a
:dependencies block with incanter as a specified dependency, so incanter
is not in your classpath and therefore will not be found when you try to
require it.

Note also that you have incorrect syntax for your require
statement. Also to be clear, (ns ... (:require ...)) does not define
dependencies. It simply loads the library into the namespace.

The correct syntax for your first block is

(ns my-kk
  (:require [incanter.core :as k]))

There is no quote before the lib spec - this is also what the error
message is telling you. If you call require as a function, then you do
need to use the quote i.e.

(require 'incanter.core :as k)

You appear to have two main problems here and that is making things
'muddy'. I'm guessing your learning clojure as well as using org babel
clojure support. You need to sort out the clojure problems first. Highly
recommend you suspend using org mode to do your clojure until your
across all the clojure specifics and have a good understanding of the
clojure environment. You will need a good understanding of how clojure
works to then be able to work out what you need to do to get it to work
with org mode. Trying to do both at the same time will just cause
confusion.

HTH

Tim

numbchild@gmail.com writes:

> I did configure `ob-clojure` with the following settings:
>
> ```elisp
> (require 'ob-clojure)
>
> ;; use CIDER as the Clojure execution backend
> (setq org-babel-clojure-backend 'cider)
>
> ;; Useful keybindings when using Clojure from Org
> ;; (org-defkey org-mode-map (kbd "C-x C-e") 'cider-eval-last-sexp)
> ;; (org-defkey org-mode-map (kbd "C-c C-d") 'cider-doc)
>
> ;; No timeout when executing calls on Cider via nrepl
> ;; (setq org-babel-clojure-sync-nrepl-timeout nil)
>
> ;; let `ob-clojure' babel src blocks allow evaluation.
> (add-to-list 'org-babel-default-header-args:clojure
>              '(:eval . "yes"))
> (add-to-list 'org-babel-default-header-args:clojure
>              '(:results . "output"))
> ;; (add-to-list 'org-babel-default-header-args:clojure
> ;;              '(:show-process . t))
> ```
>
> I start CIDER REPL session with `cider-jack-in` without project in Emacs.
>
> I changed namespace to `user` in src blocks like this:
>
> ```org
> #+BEGIN_SRC clojure
> (ns user
>   (:require '[incanter.core :as kk]))
> #+END_SRC
>
> #+RESULTS:
>
> #+BEGIN_SRC clojure :session :results output
> (print "hi")
> (def kkkk "hello")
> #+END_SRC
>
> #+RESULTS:
> : hi
> ```
>
> Then it works.
>
> Seems you're right, might my first src block can't work correctly. That
> caused second src block evaluation failed.
>
> But I require `incanter` works, I have `incanter` in Leiningen dependencies.
> ```clojure
> (require '[incanter.core :as kk])
> ```
>
> But include `incanter` in namespace failed:
> ```clojure
> (ns user
>   (:require '[incanter.core :as kk]))
> ```
> with the following error.
> ```
>   Show: Clojure Java REPL Tooling Duplicates All  (29 frames hidden)
>
> 2. Unhandled clojure.lang.Compiler$CompilerException
>    Error compiling Code/learning/Emacs/Org-mode/ob-clojure.org at (1:1)
>
>                   core.clj: 5771  clojure.core/throw-if
>                   core.clj: 5835  clojure.core/load-lib
>                   core.clj: 5832  clojure.core/load-lib
>                RestFn.java:  142  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5893  clojure.core/load-libs
>                   core.clj: 5873  clojure.core/load-libs
>                RestFn.java:  137  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5911  clojure.core/require
>                   core.clj: 5911  clojure.core/require
>                RestFn.java:  408  clojure.lang.RestFn/invoke
>                       REPL:    1  user/eval46259/loading--auto--
>                       REPL:    1  user/eval46259
>                       REPL:    1  user/eval46259
>              Compiler.java: 6977  clojure.lang.Compiler/eval
>              Compiler.java: 6966  clojure.lang.Compiler/eval
>              Compiler.java: 6940  clojure.lang.Compiler/eval
>                   core.clj: 3187  clojure.core/eval
>                   core.clj: 3183  clojure.core/eval
>                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>                   main.clj:  242  clojure.main/repl/read-eval-print
>                   main.clj:  260  clojure.main/repl/fn
>                   main.clj:  260  clojure.main/repl
>                   main.clj:  176  clojure.main/repl
>                RestFn.java: 1523  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   87
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
>                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>                   AFn.java:  144  clojure.lang.AFn/applyTo
>                   core.clj:  657  clojure.core/apply
>                   core.clj: 1963  clojure.core/with-bindings*
>                   core.clj: 1963  clojure.core/with-bindings*
>                RestFn.java:  425  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   85
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:   55
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:  222
>  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
>     interruptible_eval.clj:  190
>  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
>                   AFn.java:   22  clojure.lang.AFn/run
>    ThreadPoolExecutor.java: 1142
>  java.util.concurrent.ThreadPoolExecutor/runWorker
>    ThreadPoolExecutor.java:  617
>  java.util.concurrent.ThreadPoolExecutor$Worker/run
>                Thread.java:  745  java.lang.Thread/run
>
> 1. Caused by java.lang.Exception
>    Found lib name 'incanter.stats' containing period with prefix 'quote'.
> lib
>    names inside prefix lists must not contain periods
>
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5893  clojure.core/load-libs
>                   core.clj: 5873  clojure.core/load-libs
>                RestFn.java:  137  clojure.lang.RestFn/applyTo
>                   core.clj:  659  clojure.core/apply
>                   core.clj: 5911  clojure.core/require
>                   core.clj: 5911  clojure.core/require
>                RestFn.java:  408  clojure.lang.RestFn/invoke
>                       REPL:    1  user/eval46259/loading--auto--
>                       REPL:    1  user/eval46259
>                       REPL:    1  user/eval46259
>              Compiler.java: 6977  clojure.lang.Compiler/eval
>              Compiler.java: 6966  clojure.lang.Compiler/eval
>              Compiler.java: 6940  clojure.lang.Compiler/eval
>                   core.clj: 3187  clojure.core/eval
>                   core.clj: 3183  clojure.core/eval
>                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>                   main.clj:  242  clojure.main/repl/read-eval-print
>                   main.clj:  260  clojure.main/repl/fn
>                   main.clj:  260  clojure.main/repl
>                   main.clj:  176  clojure.main/repl
>                RestFn.java: 1523  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   87
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
>                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>                   AFn.java:  144  clojure.lang.AFn/applyTo
>                   core.clj:  657  clojure.core/apply
>                   core.clj: 1963  clojure.core/with-bindings*
>                   core.clj: 1963  clojure.core/with-bindings*
>                RestFn.java:  425  clojure.lang.RestFn/invoke
>     interruptible_eval.clj:   85
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:   55
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>     interruptible_eval.clj:  222
>  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
>     interruptible_eval.clj:  190
>  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
>                   AFn.java:   22  clojure.lang.AFn/run
>    ThreadPoolExecutor.java: 1142
>  java.util.concurrent.ThreadPoolExecutor/runWorker
>    ThreadPoolExecutor.java:  617
>  java.util.concurrent.ThreadPoolExecutor$Worker/run
>                Thread.java:  745  java.lang.Thread/run
> ```
>
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/
>
> On Sat, Jun 17, 2017 at 9:46 AM, Tim Cross <theophilusx@gmail.com> wrote:
>
>>
>> My guess is that cider is not finding the incanter package in the
>> classpath when the first block attempts to evaluate. Another issue is
>> that your not using any session options, so your two blocks will be
>> evaluated in separate environments - not a real problem with your
>> current example, but will be an issue if you expect to access incanter
>> functions from separate babel blocks.
>>
>> There are a number of working parts which all need to be lined up
>> correctly before babel clojure support will work correctly. Getting
>> things to work when your just using core clojure functions is fairly
>> trivial, but getting it to work when you have to pull in other
>> dependencies can be a little tricky.
>>
>> You might find this article useful to get started
>>
>> http://fgiasson.com/blog/index.php/2016/06/21/optimal-
>> emacs-settings-for-org-mode-for-literate-programming/
>>
>> I also notice you have not set the org-babel-clojure-backend, which you
>> need to do. My recommendation would be to do the following
>>
>> 1. Create a leinegen project to experiment with i.e.
>> lein new app my-kk
>>
>> 2. Make sure you can edit and evaluate clojure just using clojure-mode
>> and cider in emacs
>>
>> 3. Add the incanter package to your project.clj dependencies key
>>
>> 4. Modify core.clj (using clojure-mode) to include the code in your
>> clojure blocks and run with cider to make sure they work as expected.
>>
>> 5. Create the org file you want to experiment with in the root of your
>> project. This should ensure that when you try to evaluate clojure
>> blocks, the cider backend will be loaded with the dependencies in the
>> project.clj file.
>>
>> 6. Copy the code in your core.clj file into ONE babel src block and see
>> if you can get it to evaluate correctly. Experiment with the block
>> configuration options like :output etc.
>>
>> 7. Break the code up into different blocks and experiment with block
>> options, especially session options.
>>
>> Once you get to that point, you should be across the various moving
>> parts with sufficient understanding to then look at how you can tweak
>> things to get exactly the behaviour and workflow you want.
>>
>> HTH
>>
>> Tim
>>
>> numbchild@gmail.com writes:
>>
>> > When Org-mode buffer like this:
>> >
>> > #+BEGIN_SRC clojure
>> > (ns my.kk
>> >   (:require '[incanter.core :as kk]))
>> > #+END_SRC
>> >
>> > #+BEGIN_SRC clojure
>> > (print "hi")
>> > (def kkkk "hello")
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> >
>> > When I have `(ns ..)` namespace clojure code in buffer, the second
>> `(print
>> > ..)` clojure result nothing. But when I remove the first src block, the
>> > `(print ..)` clojure src block works fine.
>> >
>> > I'm using Org-mode version from `master` with `use-package` like this:
>> >
>> > (use-package org
>> >   :load-path "~/Code/Emacs/org-mode/lisp/"
>> >   :pin manual
>> >   :mode (("\\.org$" . org-mode))
>> >   :config
>> >   (use-package org-plus-contrib
>> >     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
>> >     :pin manual)
>> >   )
>> >
>> >
>> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
>> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
>> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
>> > Blog: http://stardiviner.github.io/
>>
>>
>> --
>> Tim Cross
>>


-- 
Tim Cross

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-18  1:10     ` Tim Cross
@ 2017-06-18  5:48       ` numbchild
  2017-06-21  5:12         ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: numbchild @ 2017-06-18  5:48 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 13702 bytes --]

I see, thanks very much.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sun, Jun 18, 2017 at 9:10 AM, Tim Cross <theophilusx@gmail.com> wrote:

>
> It looks like you have a combination of both clojure errors and possibly
> org babel errors. You need to sort out the clojure errors before you can
> verify there are any problems with org babel clojure support.
>
> You mention that
>
> > I start CIDER REPL session with `cider-jack-in` without project in
> > Emacs.
>
> but then you say
>
> > But I require `incanter` works, I have `incanter` in Leiningen
> > dependencies.
>
> However, if you don't have a project, then you don't have a project.clj
> file and if you don't have a project.clj file, you don't have a
> :dependencies block with incanter as a specified dependency, so incanter
> is not in your classpath and therefore will not be found when you try to
> require it.
>
> Note also that you have incorrect syntax for your require
> statement. Also to be clear, (ns ... (:require ...)) does not define
> dependencies. It simply loads the library into the namespace.
>
> The correct syntax for your first block is
>
> (ns my-kk
>   (:require [incanter.core :as k]))
>
> There is no quote before the lib spec - this is also what the error
> message is telling you. If you call require as a function, then you do
> need to use the quote i.e.
>
> (require 'incanter.core :as k)
>
> You appear to have two main problems here and that is making things
> 'muddy'. I'm guessing your learning clojure as well as using org babel
> clojure support. You need to sort out the clojure problems first. Highly
> recommend you suspend using org mode to do your clojure until your
> across all the clojure specifics and have a good understanding of the
> clojure environment. You will need a good understanding of how clojure
> works to then be able to work out what you need to do to get it to work
> with org mode. Trying to do both at the same time will just cause
> confusion.
>
> HTH
>
> Tim
>
> numbchild@gmail.com writes:
>
> > I did configure `ob-clojure` with the following settings:
> >
> > ```elisp
> > (require 'ob-clojure)
> >
> > ;; use CIDER as the Clojure execution backend
> > (setq org-babel-clojure-backend 'cider)
> >
> > ;; Useful keybindings when using Clojure from Org
> > ;; (org-defkey org-mode-map (kbd "C-x C-e") 'cider-eval-last-sexp)
> > ;; (org-defkey org-mode-map (kbd "C-c C-d") 'cider-doc)
> >
> > ;; No timeout when executing calls on Cider via nrepl
> > ;; (setq org-babel-clojure-sync-nrepl-timeout nil)
> >
> > ;; let `ob-clojure' babel src blocks allow evaluation.
> > (add-to-list 'org-babel-default-header-args:clojure
> >              '(:eval . "yes"))
> > (add-to-list 'org-babel-default-header-args:clojure
> >              '(:results . "output"))
> > ;; (add-to-list 'org-babel-default-header-args:clojure
> > ;;              '(:show-process . t))
> > ```
> >
> > I start CIDER REPL session with `cider-jack-in` without project in Emacs.
> >
> > I changed namespace to `user` in src blocks like this:
> >
> > ```org
> > #+BEGIN_SRC clojure
> > (ns user
> >   (:require '[incanter.core :as kk]))
> > #+END_SRC
> >
> > #+RESULTS:
> >
> > #+BEGIN_SRC clojure :session :results output
> > (print "hi")
> > (def kkkk "hello")
> > #+END_SRC
> >
> > #+RESULTS:
> > : hi
> > ```
> >
> > Then it works.
> >
> > Seems you're right, might my first src block can't work correctly. That
> > caused second src block evaluation failed.
> >
> > But I require `incanter` works, I have `incanter` in Leiningen
> dependencies.
> > ```clojure
> > (require '[incanter.core :as kk])
> > ```
> >
> > But include `incanter` in namespace failed:
> > ```clojure
> > (ns user
> >   (:require '[incanter.core :as kk]))
> > ```
> > with the following error.
> > ```
> >   Show: Clojure Java REPL Tooling Duplicates All  (29 frames hidden)
> >
> > 2. Unhandled clojure.lang.Compiler$CompilerException
> >    Error compiling Code/learning/Emacs/Org-mode/ob-clojure.org at (1:1)
> >
> >                   core.clj: 5771  clojure.core/throw-if
> >                   core.clj: 5835  clojure.core/load-lib
> >                   core.clj: 5832  clojure.core/load-lib
> >                RestFn.java:  142  clojure.lang.RestFn/applyTo
> >                   core.clj:  659  clojure.core/apply
> >                   core.clj: 5893  clojure.core/load-libs
> >                   core.clj: 5873  clojure.core/load-libs
> >                RestFn.java:  137  clojure.lang.RestFn/applyTo
> >                   core.clj:  659  clojure.core/apply
> >                   core.clj: 5911  clojure.core/require
> >                   core.clj: 5911  clojure.core/require
> >                RestFn.java:  408  clojure.lang.RestFn/invoke
> >                       REPL:    1  user/eval46259/loading--auto--
> >                       REPL:    1  user/eval46259
> >                       REPL:    1  user/eval46259
> >              Compiler.java: 6977  clojure.lang.Compiler/eval
> >              Compiler.java: 6966  clojure.lang.Compiler/eval
> >              Compiler.java: 6940  clojure.lang.Compiler/eval
> >                   core.clj: 3187  clojure.core/eval
> >                   core.clj: 3183  clojure.core/eval
> >                   main.clj:  242  clojure.main/repl/read-eval-print/fn
> >                   main.clj:  242  clojure.main/repl/read-eval-print
> >                   main.clj:  260  clojure.main/repl/fn
> >                   main.clj:  260  clojure.main/repl
> >                   main.clj:  176  clojure.main/repl
> >                RestFn.java: 1523  clojure.lang.RestFn/invoke
> >     interruptible_eval.clj:   87
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
> >                   AFn.java:  152  clojure.lang.AFn/applyToHelper
> >                   AFn.java:  144  clojure.lang.AFn/applyTo
> >                   core.clj:  657  clojure.core/apply
> >                   core.clj: 1963  clojure.core/with-bindings*
> >                   core.clj: 1963  clojure.core/with-bindings*
> >                RestFn.java:  425  clojure.lang.RestFn/invoke
> >     interruptible_eval.clj:   85
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> >     interruptible_eval.clj:   55
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> >     interruptible_eval.clj:  222
> >  clojure.tools.nrepl.middleware.interruptible-eval/
> interruptible-eval/fn/fn
> >     interruptible_eval.clj:  190
> >  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
> >                   AFn.java:   22  clojure.lang.AFn/run
> >    ThreadPoolExecutor.java: 1142
> >  java.util.concurrent.ThreadPoolExecutor/runWorker
> >    ThreadPoolExecutor.java:  617
> >  java.util.concurrent.ThreadPoolExecutor$Worker/run
> >                Thread.java:  745  java.lang.Thread/run
> >
> > 1. Caused by java.lang.Exception
> >    Found lib name 'incanter.stats' containing period with prefix 'quote'.
> > lib
> >    names inside prefix lists must not contain periods
> >
> >                   core.clj:  659  clojure.core/apply
> >                   core.clj: 5893  clojure.core/load-libs
> >                   core.clj: 5873  clojure.core/load-libs
> >                RestFn.java:  137  clojure.lang.RestFn/applyTo
> >                   core.clj:  659  clojure.core/apply
> >                   core.clj: 5911  clojure.core/require
> >                   core.clj: 5911  clojure.core/require
> >                RestFn.java:  408  clojure.lang.RestFn/invoke
> >                       REPL:    1  user/eval46259/loading--auto--
> >                       REPL:    1  user/eval46259
> >                       REPL:    1  user/eval46259
> >              Compiler.java: 6977  clojure.lang.Compiler/eval
> >              Compiler.java: 6966  clojure.lang.Compiler/eval
> >              Compiler.java: 6940  clojure.lang.Compiler/eval
> >                   core.clj: 3187  clojure.core/eval
> >                   core.clj: 3183  clojure.core/eval
> >                   main.clj:  242  clojure.main/repl/read-eval-print/fn
> >                   main.clj:  242  clojure.main/repl/read-eval-print
> >                   main.clj:  260  clojure.main/repl/fn
> >                   main.clj:  260  clojure.main/repl
> >                   main.clj:  176  clojure.main/repl
> >                RestFn.java: 1523  clojure.lang.RestFn/invoke
> >     interruptible_eval.clj:   87
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
> >                   AFn.java:  152  clojure.lang.AFn/applyToHelper
> >                   AFn.java:  144  clojure.lang.AFn/applyTo
> >                   core.clj:  657  clojure.core/apply
> >                   core.clj: 1963  clojure.core/with-bindings*
> >                   core.clj: 1963  clojure.core/with-bindings*
> >                RestFn.java:  425  clojure.lang.RestFn/invoke
> >     interruptible_eval.clj:   85
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> >     interruptible_eval.clj:   55
> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> >     interruptible_eval.clj:  222
> >  clojure.tools.nrepl.middleware.interruptible-eval/
> interruptible-eval/fn/fn
> >     interruptible_eval.clj:  190
> >  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
> >                   AFn.java:   22  clojure.lang.AFn/run
> >    ThreadPoolExecutor.java: 1142
> >  java.util.concurrent.ThreadPoolExecutor/runWorker
> >    ThreadPoolExecutor.java:  617
> >  java.util.concurrent.ThreadPoolExecutor$Worker/run
> >                Thread.java:  745  java.lang.Thread/run
> > ```
> >
> >
> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> > Blog: http://stardiviner.github.io/
> >
> > On Sat, Jun 17, 2017 at 9:46 AM, Tim Cross <theophilusx@gmail.com>
> wrote:
> >
> >>
> >> My guess is that cider is not finding the incanter package in the
> >> classpath when the first block attempts to evaluate. Another issue is
> >> that your not using any session options, so your two blocks will be
> >> evaluated in separate environments - not a real problem with your
> >> current example, but will be an issue if you expect to access incanter
> >> functions from separate babel blocks.
> >>
> >> There are a number of working parts which all need to be lined up
> >> correctly before babel clojure support will work correctly. Getting
> >> things to work when your just using core clojure functions is fairly
> >> trivial, but getting it to work when you have to pull in other
> >> dependencies can be a little tricky.
> >>
> >> You might find this article useful to get started
> >>
> >> http://fgiasson.com/blog/index.php/2016/06/21/optimal-
> >> emacs-settings-for-org-mode-for-literate-programming/
> >>
> >> I also notice you have not set the org-babel-clojure-backend, which you
> >> need to do. My recommendation would be to do the following
> >>
> >> 1. Create a leinegen project to experiment with i.e.
> >> lein new app my-kk
> >>
> >> 2. Make sure you can edit and evaluate clojure just using clojure-mode
> >> and cider in emacs
> >>
> >> 3. Add the incanter package to your project.clj dependencies key
> >>
> >> 4. Modify core.clj (using clojure-mode) to include the code in your
> >> clojure blocks and run with cider to make sure they work as expected.
> >>
> >> 5. Create the org file you want to experiment with in the root of your
> >> project. This should ensure that when you try to evaluate clojure
> >> blocks, the cider backend will be loaded with the dependencies in the
> >> project.clj file.
> >>
> >> 6. Copy the code in your core.clj file into ONE babel src block and see
> >> if you can get it to evaluate correctly. Experiment with the block
> >> configuration options like :output etc.
> >>
> >> 7. Break the code up into different blocks and experiment with block
> >> options, especially session options.
> >>
> >> Once you get to that point, you should be across the various moving
> >> parts with sufficient understanding to then look at how you can tweak
> >> things to get exactly the behaviour and workflow you want.
> >>
> >> HTH
> >>
> >> Tim
> >>
> >> numbchild@gmail.com writes:
> >>
> >> > When Org-mode buffer like this:
> >> >
> >> > #+BEGIN_SRC clojure
> >> > (ns my.kk
> >> >   (:require '[incanter.core :as kk]))
> >> > #+END_SRC
> >> >
> >> > #+BEGIN_SRC clojure
> >> > (print "hi")
> >> > (def kkkk "hello")
> >> > #+END_SRC
> >> >
> >> > #+RESULTS:
> >> >
> >> > When I have `(ns ..)` namespace clojure code in buffer, the second
> >> `(print
> >> > ..)` clojure result nothing. But when I remove the first src block,
> the
> >> > `(print ..)` clojure src block works fine.
> >> >
> >> > I'm using Org-mode version from `master` with `use-package` like this:
> >> >
> >> > (use-package org
> >> >   :load-path "~/Code/Emacs/org-mode/lisp/"
> >> >   :pin manual
> >> >   :mode (("\\.org$" . org-mode))
> >> >   :config
> >> >   (use-package org-plus-contrib
> >> >     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
> >> >     :pin manual)
> >> >   )
> >> >
> >> >
> >> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> >> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
> >> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> >> > Blog: http://stardiviner.github.io/
> >>
> >>
> >> --
> >> Tim Cross
> >>
>
>
> --
> Tim Cross
>

[-- Attachment #2: Type: text/html, Size: 18463 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-18  5:48       ` numbchild
@ 2017-06-21  5:12         ` numbchild
  2017-12-19  9:54           ` [UPDATE] " stardiviner
  0 siblings, 1 reply; 9+ messages in thread
From: numbchild @ 2017-06-21  5:12 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 15157 bytes --]

Hi, Tim,
Excuse my obstinacy, I still think the problem is in `ob-clojure.el`
Because when I:
```org
#+BEGIN_SRC clojure :session
(ns user-kk)
#+END_SRC

#+BEGIN_SRC clojure :session :results output
(print "hi")
(def kkkk "hello")
#+END_SRC

#+RESULTS:
```
The second block does not return result.
when I remove the first block, the second block works.
Why `ob-clojure.el` don't evaluate the first block when I press [C-c C-c]
on the second block, but still respect the first block's Clojure namespace
definition?

If it is the way `ob-clojure.el` works. I think this should have an option
to disable "respecting babel clojure namespace definition". Because I use
"Literate Programming" a lot. I will add some src blcoks with `(ns ...)` as
example in Org-mode file.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sun, Jun 18, 2017 at 1:48 PM, numbchild@gmail.com <numbchild@gmail.com>
wrote:

> I see, thanks very much.
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/
>
> On Sun, Jun 18, 2017 at 9:10 AM, Tim Cross <theophilusx@gmail.com> wrote:
>
>>
>> It looks like you have a combination of both clojure errors and possibly
>> org babel errors. You need to sort out the clojure errors before you can
>> verify there are any problems with org babel clojure support.
>>
>> You mention that
>>
>> > I start CIDER REPL session with `cider-jack-in` without project in
>> > Emacs.
>>
>> but then you say
>>
>> > But I require `incanter` works, I have `incanter` in Leiningen
>> > dependencies.
>>
>> However, if you don't have a project, then you don't have a project.clj
>> file and if you don't have a project.clj file, you don't have a
>> :dependencies block with incanter as a specified dependency, so incanter
>> is not in your classpath and therefore will not be found when you try to
>> require it.
>>
>> Note also that you have incorrect syntax for your require
>> statement. Also to be clear, (ns ... (:require ...)) does not define
>> dependencies. It simply loads the library into the namespace.
>>
>> The correct syntax for your first block is
>>
>> (ns my-kk
>>   (:require [incanter.core :as k]))
>>
>> There is no quote before the lib spec - this is also what the error
>> message is telling you. If you call require as a function, then you do
>> need to use the quote i.e.
>>
>> (require 'incanter.core :as k)
>>
>> You appear to have two main problems here and that is making things
>> 'muddy'. I'm guessing your learning clojure as well as using org babel
>> clojure support. You need to sort out the clojure problems first. Highly
>> recommend you suspend using org mode to do your clojure until your
>> across all the clojure specifics and have a good understanding of the
>> clojure environment. You will need a good understanding of how clojure
>> works to then be able to work out what you need to do to get it to work
>> with org mode. Trying to do both at the same time will just cause
>> confusion.
>>
>> HTH
>>
>> Tim
>>
>> numbchild@gmail.com writes:
>>
>> > I did configure `ob-clojure` with the following settings:
>> >
>> > ```elisp
>> > (require 'ob-clojure)
>> >
>> > ;; use CIDER as the Clojure execution backend
>> > (setq org-babel-clojure-backend 'cider)
>> >
>> > ;; Useful keybindings when using Clojure from Org
>> > ;; (org-defkey org-mode-map (kbd "C-x C-e") 'cider-eval-last-sexp)
>> > ;; (org-defkey org-mode-map (kbd "C-c C-d") 'cider-doc)
>> >
>> > ;; No timeout when executing calls on Cider via nrepl
>> > ;; (setq org-babel-clojure-sync-nrepl-timeout nil)
>> >
>> > ;; let `ob-clojure' babel src blocks allow evaluation.
>> > (add-to-list 'org-babel-default-header-args:clojure
>> >              '(:eval . "yes"))
>> > (add-to-list 'org-babel-default-header-args:clojure
>> >              '(:results . "output"))
>> > ;; (add-to-list 'org-babel-default-header-args:clojure
>> > ;;              '(:show-process . t))
>> > ```
>> >
>> > I start CIDER REPL session with `cider-jack-in` without project in
>> Emacs.
>> >
>> > I changed namespace to `user` in src blocks like this:
>> >
>> > ```org
>> > #+BEGIN_SRC clojure
>> > (ns user
>> >   (:require '[incanter.core :as kk]))
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> >
>> > #+BEGIN_SRC clojure :session :results output
>> > (print "hi")
>> > (def kkkk "hello")
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> > : hi
>> > ```
>> >
>> > Then it works.
>> >
>> > Seems you're right, might my first src block can't work correctly. That
>> > caused second src block evaluation failed.
>> >
>> > But I require `incanter` works, I have `incanter` in Leiningen
>> dependencies.
>> > ```clojure
>> > (require '[incanter.core :as kk])
>> > ```
>> >
>> > But include `incanter` in namespace failed:
>> > ```clojure
>> > (ns user
>> >   (:require '[incanter.core :as kk]))
>> > ```
>> > with the following error.
>> > ```
>> >   Show: Clojure Java REPL Tooling Duplicates All  (29 frames hidden)
>> >
>> > 2. Unhandled clojure.lang.Compiler$CompilerException
>> >    Error compiling Code/learning/Emacs/Org-mode/ob-clojure.org at (1:1)
>> >
>> >                   core.clj: 5771  clojure.core/throw-if
>> >                   core.clj: 5835  clojure.core/load-lib
>> >                   core.clj: 5832  clojure.core/load-lib
>> >                RestFn.java:  142  clojure.lang.RestFn/applyTo
>> >                   core.clj:  659  clojure.core/apply
>> >                   core.clj: 5893  clojure.core/load-libs
>> >                   core.clj: 5873  clojure.core/load-libs
>> >                RestFn.java:  137  clojure.lang.RestFn/applyTo
>> >                   core.clj:  659  clojure.core/apply
>> >                   core.clj: 5911  clojure.core/require
>> >                   core.clj: 5911  clojure.core/require
>> >                RestFn.java:  408  clojure.lang.RestFn/invoke
>> >                       REPL:    1  user/eval46259/loading--auto--
>> >                       REPL:    1  user/eval46259
>> >                       REPL:    1  user/eval46259
>> >              Compiler.java: 6977  clojure.lang.Compiler/eval
>> >              Compiler.java: 6966  clojure.lang.Compiler/eval
>> >              Compiler.java: 6940  clojure.lang.Compiler/eval
>> >                   core.clj: 3187  clojure.core/eval
>> >                   core.clj: 3183  clojure.core/eval
>> >                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>> >                   main.clj:  242  clojure.main/repl/read-eval-print
>> >                   main.clj:  260  clojure.main/repl/fn
>> >                   main.clj:  260  clojure.main/repl
>> >                   main.clj:  176  clojure.main/repl
>> >                RestFn.java: 1523  clojure.lang.RestFn/invoke
>> >     interruptible_eval.clj:   87
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
>> >                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>> >                   AFn.java:  144  clojure.lang.AFn/applyTo
>> >                   core.clj:  657  clojure.core/apply
>> >                   core.clj: 1963  clojure.core/with-bindings*
>> >                   core.clj: 1963  clojure.core/with-bindings*
>> >                RestFn.java:  425  clojure.lang.RestFn/invoke
>> >     interruptible_eval.clj:   85
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>> >     interruptible_eval.clj:   55
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>> >     interruptible_eval.clj:  222
>> >  clojure.tools.nrepl.middleware.interruptible-eval/interrupti
>> ble-eval/fn/fn
>> >     interruptible_eval.clj:  190
>> >  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
>> >                   AFn.java:   22  clojure.lang.AFn/run
>> >    ThreadPoolExecutor.java: 1142
>> >  java.util.concurrent.ThreadPoolExecutor/runWorker
>> >    ThreadPoolExecutor.java:  617
>> >  java.util.concurrent.ThreadPoolExecutor$Worker/run
>> >                Thread.java:  745  java.lang.Thread/run
>> >
>> > 1. Caused by java.lang.Exception
>> >    Found lib name 'incanter.stats' containing period with prefix
>> 'quote'.
>> > lib
>> >    names inside prefix lists must not contain periods
>> >
>> >                   core.clj:  659  clojure.core/apply
>> >                   core.clj: 5893  clojure.core/load-libs
>> >                   core.clj: 5873  clojure.core/load-libs
>> >                RestFn.java:  137  clojure.lang.RestFn/applyTo
>> >                   core.clj:  659  clojure.core/apply
>> >                   core.clj: 5911  clojure.core/require
>> >                   core.clj: 5911  clojure.core/require
>> >                RestFn.java:  408  clojure.lang.RestFn/invoke
>> >                       REPL:    1  user/eval46259/loading--auto--
>> >                       REPL:    1  user/eval46259
>> >                       REPL:    1  user/eval46259
>> >              Compiler.java: 6977  clojure.lang.Compiler/eval
>> >              Compiler.java: 6966  clojure.lang.Compiler/eval
>> >              Compiler.java: 6940  clojure.lang.Compiler/eval
>> >                   core.clj: 3187  clojure.core/eval
>> >                   core.clj: 3183  clojure.core/eval
>> >                   main.clj:  242  clojure.main/repl/read-eval-print/fn
>> >                   main.clj:  242  clojure.main/repl/read-eval-print
>> >                   main.clj:  260  clojure.main/repl/fn
>> >                   main.clj:  260  clojure.main/repl
>> >                   main.clj:  176  clojure.main/repl
>> >                RestFn.java: 1523  clojure.lang.RestFn/invoke
>> >     interruptible_eval.clj:   87
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
>> >                   AFn.java:  152  clojure.lang.AFn/applyToHelper
>> >                   AFn.java:  144  clojure.lang.AFn/applyTo
>> >                   core.clj:  657  clojure.core/apply
>> >                   core.clj: 1963  clojure.core/with-bindings*
>> >                   core.clj: 1963  clojure.core/with-bindings*
>> >                RestFn.java:  425  clojure.lang.RestFn/invoke
>> >     interruptible_eval.clj:   85
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>> >     interruptible_eval.clj:   55
>> >  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>> >     interruptible_eval.clj:  222
>> >  clojure.tools.nrepl.middleware.interruptible-eval/interrupti
>> ble-eval/fn/fn
>> >     interruptible_eval.clj:  190
>> >  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
>> >                   AFn.java:   22  clojure.lang.AFn/run
>> >    ThreadPoolExecutor.java: 1142
>> >  java.util.concurrent.ThreadPoolExecutor/runWorker
>> >    ThreadPoolExecutor.java:  617
>> >  java.util.concurrent.ThreadPoolExecutor$Worker/run
>> >                Thread.java:  745  java.lang.Thread/run
>> > ```
>> >
>> >
>> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
>> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
>> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
>> > Blog: http://stardiviner.github.io/
>> >
>> > On Sat, Jun 17, 2017 at 9:46 AM, Tim Cross <theophilusx@gmail.com>
>> wrote:
>> >
>> >>
>> >> My guess is that cider is not finding the incanter package in the
>> >> classpath when the first block attempts to evaluate. Another issue is
>> >> that your not using any session options, so your two blocks will be
>> >> evaluated in separate environments - not a real problem with your
>> >> current example, but will be an issue if you expect to access incanter
>> >> functions from separate babel blocks.
>> >>
>> >> There are a number of working parts which all need to be lined up
>> >> correctly before babel clojure support will work correctly. Getting
>> >> things to work when your just using core clojure functions is fairly
>> >> trivial, but getting it to work when you have to pull in other
>> >> dependencies can be a little tricky.
>> >>
>> >> You might find this article useful to get started
>> >>
>> >> http://fgiasson.com/blog/index.php/2016/06/21/optimal-
>> >> emacs-settings-for-org-mode-for-literate-programming/
>> >>
>> >> I also notice you have not set the org-babel-clojure-backend, which you
>> >> need to do. My recommendation would be to do the following
>> >>
>> >> 1. Create a leinegen project to experiment with i.e.
>> >> lein new app my-kk
>> >>
>> >> 2. Make sure you can edit and evaluate clojure just using clojure-mode
>> >> and cider in emacs
>> >>
>> >> 3. Add the incanter package to your project.clj dependencies key
>> >>
>> >> 4. Modify core.clj (using clojure-mode) to include the code in your
>> >> clojure blocks and run with cider to make sure they work as expected.
>> >>
>> >> 5. Create the org file you want to experiment with in the root of your
>> >> project. This should ensure that when you try to evaluate clojure
>> >> blocks, the cider backend will be loaded with the dependencies in the
>> >> project.clj file.
>> >>
>> >> 6. Copy the code in your core.clj file into ONE babel src block and see
>> >> if you can get it to evaluate correctly. Experiment with the block
>> >> configuration options like :output etc.
>> >>
>> >> 7. Break the code up into different blocks and experiment with block
>> >> options, especially session options.
>> >>
>> >> Once you get to that point, you should be across the various moving
>> >> parts with sufficient understanding to then look at how you can tweak
>> >> things to get exactly the behaviour and workflow you want.
>> >>
>> >> HTH
>> >>
>> >> Tim
>> >>
>> >> numbchild@gmail.com writes:
>> >>
>> >> > When Org-mode buffer like this:
>> >> >
>> >> > #+BEGIN_SRC clojure
>> >> > (ns my.kk
>> >> >   (:require '[incanter.core :as kk]))
>> >> > #+END_SRC
>> >> >
>> >> > #+BEGIN_SRC clojure
>> >> > (print "hi")
>> >> > (def kkkk "hello")
>> >> > #+END_SRC
>> >> >
>> >> > #+RESULTS:
>> >> >
>> >> > When I have `(ns ..)` namespace clojure code in buffer, the second
>> >> `(print
>> >> > ..)` clojure result nothing. But when I remove the first src block,
>> the
>> >> > `(print ..)` clojure src block works fine.
>> >> >
>> >> > I'm using Org-mode version from `master` with `use-package` like
>> this:
>> >> >
>> >> > (use-package org
>> >> >   :load-path "~/Code/Emacs/org-mode/lisp/"
>> >> >   :pin manual
>> >> >   :mode (("\\.org$" . org-mode))
>> >> >   :config
>> >> >   (use-package org-plus-contrib
>> >> >     :load-path "~/Code/Emacs/org-mode/contrib/lisp/"
>> >> >     :pin manual)
>> >> >   )
>> >> >
>> >> >
>> >> > [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
>> >> > IRC(freeenode): stardiviner                     Twitter:  @numbchild
>> >> > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
>> >> > Blog: http://stardiviner.github.io/
>> >>
>> >>
>> >> --
>> >> Tim Cross
>> >>
>>
>>
>> --
>> Tim Cross
>>
>
>

[-- Attachment #2: Type: text/html, Size: 21987 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [UPDATE] Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-06-21  5:12         ` numbchild
@ 2017-12-19  9:54           ` stardiviner
  2017-12-21 10:15             ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: stardiviner @ 2017-12-19  9:54 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

I got new update on this issue.

I think it is caused by `(clojure-find-ns)`.
Here is my found:

I created a simple clojure project for used by all org-babel-clojure src 
blocks.
```elisp
(progn
   (find-file (expand-file-name 
"~/.emacs.d/Org-mode/ob-clojure/src/ob_clojure/core.clj"))
   (cider-jack-in))
```

I edebug the `org-babel-execute:clojure` process,

`org-babel-execute:clojure' has a step: ~(clojure-find-ns)~ .
This is from ~clojure-mode~. It will find current clojure buffer 
possible clojure namespace (even in org-mode). When I the following 
example org-mode buffer, it will return "namespace-not-found" error in 
nrepl response dict. Then src blcok has no error, not results.

```org
#+BEGIN_SRC clojure :session
(in-ns 'user-kk)
or
(ns user-kk)
#+END_SRC

#+BEGIN_SRC clojure :results output
(print "hi")
#+END_SRC
```

Here is a part of function `clojure-find-ns`:

       #+begin_src emacs-lisp
       (when (or (re-search-backward clojure-namespace-name-regex nil t)
                 ;; Or any form at all.
                 (and (goto-char (point-min))
                      (re-search-forward clojure-namespace-name-regex 
nil t)))
         (match-string-no-properties 4))
       #+end_src

So I created an PR to disable find namespace in Org-mode buffer:
https://github.com/clojure-emacs/clojure-mode/pull/465

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [UPDATE] Re: ob-clojure evaluate error when Org-mode buffer has ns clojure code
  2017-12-19  9:54           ` [UPDATE] " stardiviner
@ 2017-12-21 10:15             ` numbchild
  0 siblings, 0 replies; 9+ messages in thread
From: numbchild @ 2017-12-21 10:15 UTC (permalink / raw)
  To: Tim Cross; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 2676 bytes --]

Finally found a solution. really hard. spend a lot of time on this issue.
The discussion is at here:
https://github.com/clojure-emacs/clojure-mode/pull/465 Here is my final
source code. paste here as a copy. Hope can help someone want same thing.

;; auto start CIDER REPL session in a complete Leiningen project
environment for Org-mode Babel by jack-in.
(add-to-list 'org-babel-default-header-args:clojure
             '(:session . "*cider-repl ob-clojure*"))
(progn
  (find-file (expand-file-name
"~/.emacs.d/Org-mode/ob-clojure/src/ob_clojure/core.clj"))
  (cider-jack-in))

(defun ob-clojure-cider-do-not-find-ns ()
  "Fix the issue that `cider-current-ns' try to invoke
`clojure-find-ns' to extract ns from buffer."
  (with-current-buffer "*cider-repl ob-clojure*"
    (defvar ob-clojure-cider-repl-ns cider-buffer-ns)
    (setq-local cider-buffer-ns ob-clojuure-cider-repl-ns)))
(add-hook 'org-mode-hook #'ob-clojure-cider-do-not-find-ns)



[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Tue, Dec 19, 2017 at 5:54 PM, stardiviner <numbchild@gmail.com> wrote:

> I got new update on this issue.
>
> I think it is caused by `(clojure-find-ns)`.
> Here is my found:
>
> I created a simple clojure project for used by all org-babel-clojure src
> blocks.
> ```elisp
> (progn
>   (find-file (expand-file-name "~/.emacs.d/Org-mode/ob-clojur
> e/src/ob_clojure/core.clj"))
>   (cider-jack-in))
> ```
>
> I edebug the `org-babel-execute:clojure` process,
>
> `org-babel-execute:clojure' has a step: ~(clojure-find-ns)~ .
> This is from ~clojure-mode~. It will find current clojure buffer possible
> clojure namespace (even in org-mode). When I the following example org-mode
> buffer, it will return "namespace-not-found" error in nrepl response dict.
> Then src blcok has no error, not results.
>
> ```org
> #+BEGIN_SRC clojure :session
> (in-ns 'user-kk)
> or
> (ns user-kk)
> #+END_SRC
>
> #+BEGIN_SRC clojure :results output
> (print "hi")
> #+END_SRC
> ```
>
> Here is a part of function `clojure-find-ns`:
>
>       #+begin_src emacs-lisp
>       (when (or (re-search-backward clojure-namespace-name-regex nil t)
>                 ;; Or any form at all.
>                 (and (goto-char (point-min))
>                      (re-search-forward clojure-namespace-name-regex nil
> t)))
>         (match-string-no-properties 4))
>       #+end_src
>
> So I created an PR to disable find namespace in Org-mode buffer:
> https://github.com/clojure-emacs/clojure-mode/pull/465
>

[-- Attachment #2: Type: text/html, Size: 3831 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-12-21 10:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-16 15:36 ob-clojure evaluate error when Org-mode buffer has ns clojure code numbchild
2017-06-17  1:46 ` Tim Cross
2017-06-17 12:57   ` numbchild
2017-06-17 13:26     ` numbchild
2017-06-18  1:10     ` Tim Cross
2017-06-18  5:48       ` numbchild
2017-06-21  5:12         ` numbchild
2017-12-19  9:54           ` [UPDATE] " stardiviner
2017-12-21 10:15             ` numbchild

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.