Re: [O] ob-clojure with tangling current broken

2019-01-22 Thread stardiviner


Frederick Giasson  writes:

> Hi,
>
>  That's why I added a patch recently. Now Nicolas already applied my
>  patch. You should already seen it now.
>
> Yeah I just received that email right after I sent mine. Didn't know it was 
> in the pipeline, I just re-subscribed to the mailing list.
>  
>  >
>  > It turns out that the culprit is the following line:
>  > https://code.orgmode.org/bzg/org-mode/src/master/lisp/ob-clojure.el#L108
>  >
>  > I am wondering why is there such code injection in
>  > "org-babel-expand-body:clojure". It looks like to be related to the 
> Clojure code
>  > block execution, but it also appears to be called from the tangling 
> function.
>  > Clearly those two different use cases needs to be properly handled at the 
> level
>  > of "ob-clojure.el"
>  >
>
>  Expanding clojure code is necessary to tangling, because when user have
>  noweb reference etc in source block, expanding here is necessary.
>
> Yes, that is right. What I was referring to I guess is to handle that case 
> (tangling vs. code block execution within Emacs), which is what this patch is 
> about,
> thanks!
>  
>  
>  > I didn't follow all the changes to the "ob-clojure" mode in the last year 
> or so,
>  > so please pardon my ignorance if the module is taking a different 
> direction than
>  > I am used to. Is there a rational behind this behaviour or is there a new 
> feature
>  > that I am not aware of which properly handle those two use cases?
>  >
>
>  Which part you don't understand, I might can answer your question,
>  because I did most of those changes in last year.
>
> The only thing I meant here is that the last time I looked into this code, it 
> was quite different, you guys appears to have worked a lot on it.
>
> Another thing I discovered is the =ob-clojure-literate=, but even after 
> reading its [sparse] doc and its code, I am not sure what it concretely adds 
> to =ob-clojure=
>
> Thanks for this work!

Well, about this, you can read related things, here is the original
repo: https://github.com/stardiviner/ob-clojure-literate. In the README,
I describe my motivation.

Before CIDER added "sesman" session manager, CIDER was not able to
manage sessions easily. But ob-clojure need a session. So I created it,
then I added some thing that I need for Clojure literate programming in
Org Mode.

About this extra library, here is what I think, keep it for a while,
until no one or very rare use it, I will remove it from Org Mode
contrib. Until now, no one except you asked me about what it is.

BTW, I migrated some features into core/ob-clojure.el already, like
session initialization. Specify session.

Here is the list I collate right now.

- [X] auto start REPL if necessary
  - [X] It's taken by CIDER sesman [Commit 2c5df17ed]
- [X] use default session
  - [X] It's taken by CIDER sesman, now can easily switch session.
- [ ] specify session in header argument :session, Org Babel has =[C-c C-v C-j]=
  by default.
  - [ ] provide interactive completion candidates of CIDER REPL connections
- [X] initiate session =[C-c C-v z]= [Commit 4456dc880]
  - [X] CIDER use sesman to manage REPL session now.
- [ ] support ob-core.el switch to corresponding session REPL buffer =[C-c C-v 
z]=
- [X] dynamic clojure ns [Commit d7e12d1df]
  - [X] implemented with ~:ns~ header argument [Commit d7e12d1df]
- [X] generate plot image in specific directory
  - [X] pass dir as variable into Clojure code
- [X] org babel support graphics image file link as result [Commit b088389c6]
  - [X] I add this header argument value in commit already. [Commit 296b0de4e]

If you want to read ob-clojure-literate.el source code, I suggest you
read one commit by one. It will be much clear. You can search my name
"stardiviner" and filter commits with "ob-clojure,ob-clojure-literate"
in log.

>
> Take care,
>
> Fred

Hope this will help you, Regards.

-- 
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
  



Re: [O] ob-clojure with tangling current broken

2019-01-22 Thread Frederick Giasson
Hi,

That's why I added a patch recently. Now Nicolas already applied my
> patch. You should already seen it now.
>

Yeah I just received that email right after I sent mine. Didn't know it was
in the pipeline, I just re-subscribed to the mailing list.


> >
> > It turns out that the culprit is the following line:
> > https://code.orgmode.org/bzg/org-mode/src/master/lisp/ob-clojure.el#L108
> >
> > I am wondering why is there such code injection in
> > "org-babel-expand-body:clojure". It looks like to be related to the
> Clojure code
> > block execution, but it also appears to be called from the tangling
> function.
> > Clearly those two different use cases needs to be properly handled at
> the level
> > of "ob-clojure.el"
> >
>
> Expanding clojure code is necessary to tangling, because when user have
> noweb reference etc in source block, expanding here is necessary.
>

Yes, that is right. What I was referring to I guess is to handle that case
(tangling vs. code block execution within Emacs), which is what this patch
is about, thanks!


>
> > I didn't follow all the changes to the "ob-clojure" mode in the last
> year or so,
> > so please pardon my ignorance if the module is taking a different
> direction than
> > I am used to. Is there a rational behind this behaviour or is there a
> new feature
> > that I am not aware of which properly handle those two use cases?
> >
>
> Which part you don't understand, I might can answer your question,
> because I did most of those changes in last year.
>

The only thing I meant here is that the last time I looked into this code,
it was quite different, you guys appears to have worked a lot on it.

Another thing I discovered is the =ob-clojure-literate=, but even after
reading its [sparse] doc and its code, I am not sure what it concretely
adds to =ob-clojure=

Thanks for this work!

Take care,

Fred


Re: [O] ob-clojure with tangling current broken

2019-01-21 Thread stardiviner


Frederick Giasson  writes:

> Hi,
>
> I updated org-mode to latest dev version recently and I was wondering why I 
> was
> seeing namespaces appended to each [clojure] code block I was tangling (which
> generates unusable tangled Clojure source files)


That's why I added a patch recently. Now Nicolas already applied my
patch. You should already seen it now.

>
> It turns out that the culprit is the following line:
> https://code.orgmode.org/bzg/org-mode/src/master/lisp/ob-clojure.el#L108
>
> I am wondering why is there such code injection in
> "org-babel-expand-body:clojure". It looks like to be related to the Clojure 
> code
> block execution, but it also appears to be called from the tangling function.
> Clearly those two different use cases needs to be properly handled at the 
> level
> of "ob-clojure.el"
>

Expanding clojure code is necessary to tangling, because when user have
noweb reference etc in source block, expanding here is necessary.

> I didn't follow all the changes to the "ob-clojure" mode in the last year or 
> so,
> so please pardon my ignorance if the module is taking a different direction 
> than
> I am used to. Is there a rational behind this behaviour or is there a new 
> feature
> that I am not aware of which properly handle those two use cases?
>

Which part you don't understand, I might can answer your question,
because I did most of those changes in last year.

> Thanks,
>
> Take care,
>
> Fred


--
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2019-01-13 Thread stardiviner

I updated the patch by adding a test.

With command "make test" I got:

```
Tangled 0 code blocks from babel.org
   passed  132/828  ob-tangle/no-excessive-id-insertion-on-tangle
   passed  133/828  ob-test/org-babel-combine-header-arg-lists
   failed  134/828  org-missing-dependency/test-ob-R
   failed  135/828  org-missing-dependency/test-ob-clojure
   failed  136/828  org-missing-dependency/test-ob-eshell
   failed  137/828  org-missing-dependency/test-ob-lua
   failed  138/828  org-missing-dependency/test-ob-maxima
   failed  139/828  org-missing-dependency/test-ob-plantuml
   failed  140/828  org-missing-dependency/test-ob-ruby
   failed  141/828  org-missing-dependency/test-ob-scheme
   failed  142/828  org-missing-dependency/test-ob-vala
   failed  143/828  org-missing-dependency/test-org-attach-annex
   failed  144/828  org-missing-dependency/test-org-protocol
   passed  145/828  test-ob-exp/org-babel-exp-src-blocks/w-no-file
   passed  146/828  test-ob-exp/org-babel-exp-src-blocks/w-no-headers
   passed  147/828  test-ob-exp/org-babel-exp-src-blocks/w-no-headers2
executing Emacs-Lisp code block...
```

With command:

$ make BTEST_RE="ob-clojure/tangle-without-ns" test-dirty

I got:

```
Loading 
/home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-property-inheritance.el 
(source)...
selected tests: ob-clojure/tangle-without-ns
Running 0 tests (2019-01-14 13:27:58+0800)

Ran 0 tests, 0 results as expected (2019-01-14 13:27:58+0800)

make cleantest
```

I don't know why it report missing requirement, so the test failed.

Nicolas, do you have any idea why this? You can check out the test code.

>From 8a64ccf659afcbd510e69eaa4ac175946f1ae311 Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Thu, 10 Jan 2019 09:34:39 +0800
Subject: [PATCH] lisp/ob-clojure.el: Don't tangle with auto prepend ns
 statement

* lisp/ob-clojure.el: (org-babel-expand-body:clojure,
  org-babel-header-args:clojure): whether auto prepend Clojure (ns ..)
  statement depend on whether have :ns header argument specified.

* etc/ORG-NEWS: mentioned this changed in ORG-NEWS.

* testing/test-ob-clojure.el: add a test for tangled clojure code
  without (ns ..).
---
 etc/ORG-NEWS|  5 +
 lisp/ob-clojure.el  | 34 ++---
 testing/lisp/test-ob-clojure.el | 14 ++
 3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1bb485ad1..2eea00d97 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 * Version 9.3
 
 ** Incompatible changes
+*** ob-clojure will not auto prepend ~(ns ..)~ statement now
+When tangling, user usually just want to tangle literally code instead
+of prepend inserting a ~(ns ..)~ statement before source block
+code. Now, when you have no ~:ns~ header argument specified, this
+behavior will not happend automatically.
 *** Change in behavior on exit from an Org edit buffer
 Org will no longer attempt to restore the window configuration in the
 frame to which the user returns after editing a source block with
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 2088ab375..55a4c3eb4 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -63,7 +63,11 @@
 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
 
 (defvar org-babel-default-header-args:clojure '())
-(defvar org-babel-header-args:clojure '((package . :any)))
+(defvar org-babel-header-args:clojure '((package . :any))
+  "For the :ns header argument, when you don't specify it, it
+  will not auto prepend (ns ..) statement before source block
+  code. If you have a :ns specified, the (ns ..) statement will
+  be auto prepended before source block code.")
 
 (defcustom org-babel-clojure-sync-nrepl-timeout 10
   "Timeout value, in seconds, of a Clojure sync call.
@@ -103,20 +107,20 @@ If the value is nil, timeout is disabled."
 	 (result-params (cdr (assq :result-params params)))
 	 (print-level nil)
 	 (print-length nil)
-	 (body
-	  (org-trim
-	   (format "(ns %s)\n%s"
-		   ;; Source block specified namespace :ns.
-		   ns
-		   ;; Variables binding.
-		   (if (null vars) (org-trim body)
-		 (format "(let [%s]\n%s)"
-			 (mapconcat
-			  (lambda (var)
-(format "%S (quote %S)" (car var) (cdr var)))
-			  vars
-			  "\n  ")
-			 body))
+	 (body (org-trim
+		(concat
+		 ;; Source block specified namespace :ns.
+		 (if (not (null (cdr (assq :ns params
+		 (format "(ns %s)\n" ns))
+		 ;; Variables binding.
+		 (if (null vars) (org-trim body)
+		   (format "(let [%s]\n%s)"
+			   (mapconcat
+			(lambda (var)
+			  (format "%S (quote %S)" (car var) (cdr var)))
+			vars
+			"\n  ")
+			   body))
 (if (or (member "code" result-params)
 	(member "pp" result-params))
 	(format "(clojure.pprint/pprint (do %s))" body)
diff --git a/testing/lisp/test-ob-clojure.el b/testing/lisp/test-ob-clojure.el

Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2019-01-09 Thread stardiviner

stardiviner  writes:

> The ob-clojure tangle will insert ~(ns ..)~ from babel header argument :ns or 
> use defualt ~(ns user)~.
>
>#+begin_src clojure :eval no :ns "" :tangle 
> "data/code/xunfei-clj-demo/project.clj" :results link :file 
> "data/code/xunfei-clj-demo/project.clj"
>(defproject xunfei-clj-demo "0.1.0-SNAPSHOT"
>  :description "xunfei-clj demo"
>  :url "http://example.com/FIXME;
>  :license {:name "Eclipse Public License"
>:url  "http://www.eclipse.org/legal/epl-v10.html"}
>  :dependencies [[org.clojure/clojure "1.9.0"]
> [xunfei-clj "0.1.4-SNAPSHOT"]]
>  :resource-paths ["lib/Msc.jar"])
>#+end_src
>
> In upper case, obviously I don't want insert the ~(ns ..)~ line of code.
>
> I hope the ob-clojure header argument ~:ns~ should detect value like
> "nil", "" (empty string) or something else. Or when ~:ns~ header
> argument is not specified. So that the tangling will not auto insert
> ~(ns ..)~ line.

I added an patch to detect :ns is not specified which is `nil'. This
will be better for tangling.

>From 749e85a30ca6226c4b3aaef85ae0d72b51d6018e Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Thu, 10 Jan 2019 09:34:39 +0800
Subject: [PATCH] lisp/ob-clojure.el: Don't tangle with auto prepend ns
 statement

* lisp/ob-clojure.el: (org-babel-expand-body:clojure,
  org-babel-header-args:clojure): whether auto prepend Clojure (ns ..)
  statement depend on whether have :ns header argument specified.

* etc/ORG-NEWS: mentioned this changed in ORG-NEWS.
---
 etc/ORG-NEWS   |  5 +
 lisp/ob-clojure.el | 34 +++---
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1bb485ad1..2eea00d97 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 * Version 9.3
 
 ** Incompatible changes
+*** ob-clojure will not auto prepend ~(ns ..)~ statement now
+When tangling, user usually just want to tangle literally code instead
+of prepend inserting a ~(ns ..)~ statement before source block
+code. Now, when you have no ~:ns~ header argument specified, this
+behavior will not happend automatically.
 *** Change in behavior on exit from an Org edit buffer
 Org will no longer attempt to restore the window configuration in the
 frame to which the user returns after editing a source block with
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 2088ab375..55a4c3eb4 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -63,7 +63,11 @@
 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
 
 (defvar org-babel-default-header-args:clojure '())
-(defvar org-babel-header-args:clojure '((package . :any)))
+(defvar org-babel-header-args:clojure '((package . :any))
+  "For the :ns header argument, when you don't specify it, it
+  will not auto prepend (ns ..) statement before source block
+  code. If you have a :ns specified, the (ns ..) statement will
+  be auto prepended before source block code.")
 
 (defcustom org-babel-clojure-sync-nrepl-timeout 10
   "Timeout value, in seconds, of a Clojure sync call.
@@ -103,20 +107,20 @@ If the value is nil, timeout is disabled."
 	 (result-params (cdr (assq :result-params params)))
 	 (print-level nil)
 	 (print-length nil)
-	 (body
-	  (org-trim
-	   (format "(ns %s)\n%s"
-		   ;; Source block specified namespace :ns.
-		   ns
-		   ;; Variables binding.
-		   (if (null vars) (org-trim body)
-		 (format "(let [%s]\n%s)"
-			 (mapconcat
-			  (lambda (var)
-(format "%S (quote %S)" (car var) (cdr var)))
-			  vars
-			  "\n  ")
-			 body))
+	 (body (org-trim
+		(concat
+		 ;; Source block specified namespace :ns.
+		 (if (not (null (cdr (assq :ns params
+		 (format "(ns %s)\n" ns))
+		 ;; Variables binding.
+		 (if (null vars) (org-trim body)
+		   (format "(let [%s]\n%s)"
+			   (mapconcat
+			(lambda (var)
+			  (format "%S (quote %S)" (car var) (cdr var)))
+			vars
+			"\n  ")
+			   body))
 (if (or (member "code" result-params)
 	(member "pp" result-params))
 	(format "(clojure.pprint/pprint (do %s))" body)
-- 
2.20.1



-- 
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
  


Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2018-12-05 Thread stardiviner


Tim Cross  writes:

> Sorry, only just noticed this response in my spam folder - gmail is
> tagging your messages as spam because it could not verify it was legit.

Yeah, I found some other's emails in Gmail Spam too. I usually regularly
check Spam folder a week. Might because GPG sign? I don't know why.

> I will have leave in the early year and will likely re-visit this. I too
> need to move from lein to clj + edn. It would be really good to simplify
> the org interface for clojre and clojurescript and I suspect clj + edn
> will be the way to go. The older inf-clojure was OK, but it lacked some
> higher level features we do need as well, so it will take a bit of work.

I'm currently switched to clj-new utility. I'm considering create an
Emacs extension to invoke "clj-new". I'll start work on it in a few days.

--
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2018-12-04 Thread Tim Cross


Sorry, only just noticed this response in my spam folder - gmail is
tagging your messages as spam because it could not verify it was legit.

stardiviner  writes:

> Tim Cross  writes:
>
>> I think the problem here is that really, project.clj is not a valid
>> clojure source file. It is really a clojure data file or clojure
>> snippet (I mean in the sense that you cannot execute it or include it as
>> a dependency within a clojure program - it is input data for the lein
>> build tool). If lein was being developed from scratch today, rather than
>> project.clj, you would probably have project.edn.
>
> Actually a few months ago, Sean on Slack clojurians helped me out for
> using clj and deps.edn. Just because of habit inertia. I'm still using
> Leiningen. As you said, the Clojure community is moving to clj/clojure +
> deps.edn. I decide to following the trend. Start to use it now.
>
>>
>> The question is, should we allow setting ns to nil/"", preventing
>> inclusion of a ns line, which would make 'real' clojure source files
>> invalid just to support this edge case or should we consider an
>> alternative solution e.g.
>>
>> - have a 'lein-project' source type which could perhaps provide
>>   additional support for editing project.clj files (as I suspect lein is
>>   on the way out - replaced with things like clj or boot)
>> - try using edn-mode and having support for edn as a valid language
>>   type. I've never used edn mode and I'm not 100% certain project.clj
>>   and edn are completely compatible.
>>
>> It seems to me that the preferred build tool is likely to become clj or
>> derivatives of clj. I've noticed increasingly longer delays in new lein
>> releases (the 'reflection' warning has been there for nearly 12 months
>> now, as has the incorrect classpath warning on some platforms).
>>
>> In the long-term, I think org would probably benefit from integration
>> with clj rather than cider for ob-clojure as it is likely to be more
>> stable and less complex. Using cider has always felt like pushing a
>> square peg into a round hole to me.
>
> I remember we have a short discussion about ob-clojure use clj instead
> of CIDER before. I totally agree on this. Seems already has an Emacs
> package named "inf-clojure". I added this "integrate inf-clojure to
> ob-clojure" as my task. But not sure when to check it out. I have many
> tasks on my list. I have an idea, would you create an GitHub repo for
> this? I would like to contribute on it.
>
> As I said previous, if I use "deps.edn", use `edn-mode' would solve this
> problem. But there is no `edn-mode'. I checked out MELPA, only has
> package named "edn" which is used to Support for reading and writing the
> edn data format from elisp. I also did a search on GitHub. No luck.
>
> Anyway, I'm going to switch to clj + deps.edn
>
> And Thanks, @Tim.

At present, I have no time to work on any clojure. I'm completely
consumed with work demands and unfortunately, I've not convinced them to
allow me to use Clojre/clojurescript (yet!), so stuck in javascript
world for now.

I will have leave in the early year and will likely re-visit this. I too
need to move from lein to clj + edn. It would be really good to simplify
the org interface for clojre and clojurescript and I suspect clj + edn
will be the way to go. The older inf-clojure was OK, but it lacked some
higher level features we do need as well, so it will take a bit of work.

Tim


-- 
Tim Cross



Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2018-12-02 Thread stardiviner


Tim Cross  writes:

> I think the problem here is that really, project.clj is not a valid
> clojure source file. It is really a clojure data file or clojure
> snippet (I mean in the sense that you cannot execute it or include it as
> a dependency within a clojure program - it is input data for the lein
> build tool). If lein was being developed from scratch today, rather than
> project.clj, you would probably have project.edn.

Actually a few months ago, Sean on Slack clojurians helped me out for
using clj and deps.edn. Just because of habit inertia. I'm still using
Leiningen. As you said, the Clojure community is moving to clj/clojure +
deps.edn. I decide to following the trend. Start to use it now.

>
> The question is, should we allow setting ns to nil/"", preventing
> inclusion of a ns line, which would make 'real' clojure source files
> invalid just to support this edge case or should we consider an
> alternative solution e.g.
>
> - have a 'lein-project' source type which could perhaps provide
>   additional support for editing project.clj files (as I suspect lein is
>   on the way out - replaced with things like clj or boot)
> - try using edn-mode and having support for edn as a valid language
>   type. I've never used edn mode and I'm not 100% certain project.clj
>   and edn are completely compatible.
>
> It seems to me that the preferred build tool is likely to become clj or
> derivatives of clj. I've noticed increasingly longer delays in new lein
> releases (the 'reflection' warning has been there for nearly 12 months
> now, as has the incorrect classpath warning on some platforms).
>
> In the long-term, I think org would probably benefit from integration
> with clj rather than cider for ob-clojure as it is likely to be more
> stable and less complex. Using cider has always felt like pushing a
> square peg into a round hole to me.

I remember we have a short discussion about ob-clojure use clj instead
of CIDER before. I totally agree on this. Seems already has an Emacs
package named "inf-clojure". I added this "integrate inf-clojure to
ob-clojure" as my task. But not sure when to check it out. I have many
tasks on my list. I have an idea, would you create an GitHub repo for
this? I would like to contribute on it.

As I said previous, if I use "deps.edn", use `edn-mode' would solve this
problem. But there is no `edn-mode'. I checked out MELPA, only has
package named "edn" which is used to Support for reading and writing the
edn data format from elisp. I also did a search on GitHub. No luck.

Anyway, I'm going to switch to clj + deps.edn

And Thanks, @Tim.

--
[ stardiviner ]
   I try to make every word tell the meaning what I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3



Re: [O] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.

2018-11-30 Thread Tim Cross


stardiviner  writes:

> The ob-clojure tangle will insert ~(ns ..)~ from babel header argument :ns or 
> use defualt ~(ns user)~.
>
>#+begin_src clojure :eval no :ns "" :tangle 
> "data/code/xunfei-clj-demo/project.clj" :results link :file 
> "data/code/xunfei-clj-demo/project.clj"
>(defproject xunfei-clj-demo "0.1.0-SNAPSHOT"
>  :description "xunfei-clj demo"
>  :url "http://example.com/FIXME;
>  :license {:name "Eclipse Public License"
>:url  "http://www.eclipse.org/legal/epl-v10.html"}
>  :dependencies [[org.clojure/clojure "1.9.0"]
> [xunfei-clj "0.1.4-SNAPSHOT"]]
>  :resource-paths ["lib/Msc.jar"])
>#+end_src
>
> In upper case, obviously I don't want insert the ~(ns ..)~ line of code.
>
> I hope the ob-clojure header argument ~:ns~ should detect value like
> "nil", "" (empty string) or something else. Or when ~:ns~ header
> argument is not specified. So that the tangling will not auto insert
> ~(ns ..)~ line.

I think the problem here is that really, project.clj is not a valid
clojure source file. It is really a clojure data file or clojure
snippet (I mean in the sense that you cannot execute it or include it as
a dependency within a clojure program - it is input data for the lein
build tool). If lein was being developed from scratch today, rather than
project.clj, you would probably have project.edn.

The question is, should we allow setting ns to nil/"", preventing
inclusion of a ns line, which would make 'real' clojure source files
invalid just to support this edge case or should we consider an
alternative solution e.g.

- have a 'lein-project' source type which could perhaps provide
  additional support for editing project.clj files (as I suspect lein is
  on the way out - replaced with things like clj or boot)
- try using edn-mode and having support for edn as a valid language
  type. I've never used edn mode and I'm not 100% certain project.clj
  and edn are completely compatible.

It seems to me that the preferred build tool is likely to become clj or
derivatives of clj. I've noticed increasingly longer delays in new lein
releases (the 'reflection' warning has been there for nearly 12 months
now, as has the incorrect classpath warning on some platforms).

In the long-term, I think org would probably benefit from integration
with clj rather than cider for ob-clojure as it is likely to be more
stable and less complex. Using cider has always felt like pushing a
square peg into a round hole to me. 

Tim

--
Tim Cross



Re: [O] ob-clojure will error result when contains comment

2017-07-13 Thread Tim Cross
Your second block can't run in a repl unless you have additional
definitions you are not showing here. The error messages are complaining
that

1. There is no function called sum. Clojure does not have a sum function
and your not defining one in this block, so that makes perfect sense.

2. The function avg1 is unbound. This also makes perfect sense because the
line where you try to bind avg1 is the same line where the error about sum
is generated, which means that binding failed.

The additional settings you are using might be contributing to your
problems - I don't know I don't have any additional default header args. I
would remove them and only set them once you know you have things working
with normal/standard src block settings.

The fact I cannot reproduce your errors with a stock setup indicates the
problem is still something with your environment.

On 13 July 2017 at 22:23, numbch...@gmail.com  wrote:

> I run the both blocks fine in CIDER REPL, that's weird.
> I have the following special settings for ob-clojure.
> ```elisp
> (add-to-list 'org-babel-default-header-args:clojure
>  '(:eval . "yes"))
> (add-to-list 'org-babel-default-header-args:clojure
>  '(:results . "value pp"))
> (add-to-list 'org-babel-default-header-args:clojure ; for Clojure
> `dotimes' etc.
>  '(:show-process . "no"))
> (add-to-list 'org-babel-default-header-args:clojure
>  '(:noweb . "yes"))
> ```
>
>
> [stardiviner] 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 Thu, Jul 13, 2017 at 4:48 PM, Tim Cross  wrote:
>
>>
>> I think there is something wrong with your environment and your second
>> block is not legal code. If you run your second block directly in a
>> clojure repl, you will get the same errors, which means it isn't an org
>> issue.
>>
>> Executing your examples with org from master branch I get
>>
>> #+BEGIN_SRC clojure
>> (+ 1 1) ;=> 2
>> #+END_SRC
>>
>> #+RESULTS:
>> : 2
>>
>> #+BEGIN_SRC clojure :results value
>> (def sum1 #(reduce + %))
>> (def avg1 #(/ (sum %) (count %)))
>>
>> (defn stats
>>   [numbers]
>>   (map #(% numbers) [sum1 count avg1]))
>>
>> (stats [3 4 10])
>>
>> (stats [80 1 44 13 6])
>>
>> #+END_SRC
>>
>> #+RESULTS:
>> : #'user/sum1#'user/statsclass clojure.lang.Compiler$CompilerExceptionclass
>> java.lang.IllegalStateExceptionclass java.lang.IllegalStateExceptionclass
>> clojure.lang.Compiler$CompilerExceptionclass
>> java.lang.IllegalStateExceptionclass 
>> java.lang.IllegalStateExceptionCompilerException
>> java.lang.RuntimeException: Unable to resolve symbol: sum in this context,
>> compiling:(/tmp/form-init6637865895670060372.clj:2:15)
>> : IllegalStateException Attempting to call unbound fn: #'user/avg1
>> clojure.lang.Var$Unbound.throwArity (Var.java:43)
>> : IllegalStateException Attempting to call unbound fn: #'user/avg1
>> clojure.lang.Var$Unbound.throwArity (Var.java:43)
>>
>> I'm not sure why the version of ob-clojure.el is not yet in the org or
>> org-plus-contrib packages - Does master only become maint after major
>> version releases?
>>
>> Note also, there appears to be an issue with most recent versions of
>> cider when you do cider-jack-in and your not inside a project. The
>> issues seem to relate mainly to clj-refactor, but there could be other
>> problems. Again, highly recommend running your cider inside a clojure
>> project.
>>
>> Tim
>>
>> numbch...@gmail.com writes:
>>
>> > Here is the examples:
>> >
>> > #+BEGIN_SRC clojure
>> > (+ 1 1) ;=> 2
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> > : class clojure.lang.LispReader$ReaderExceptionclass
>> > java.lang.RuntimeExceptionRuntimeException EOF while reading, starting
>> at
>> > line 1  clojure.lang.Util.runtimeException (Util.java:221)
>> >
>> > #+BEGIN_SRC clojure :results value
>> > (def sum1 #(reduce + %))
>> > (def avg1 #(/ (sum %) (count %)))
>> >
>> > (defn stats
>> >   [numbers]
>> >   (map #(% numbers) [sum1 count avg1]))
>> >
>> > (stats [3 4 10])
>> > ;; => (17 3 17/3)
>> >
>> > (stats [80 1 44 13 6])
>> > ;; => (144 5 144/5)
>> > #+END_SRC
>> >
>> > #+RESULTS:
>> > : class clojure.lang.LispReader$ReaderExceptionclass
>> > java.lang.RuntimeExceptionRuntimeException EOF while reading, starting
>> at
>> > line 1  clojure.lang.Util.runtimeException (Util.java:221)
>> >
>> >
>> > [stardiviner] 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
>>
>
>


-- 
regards,

Tim

--
Tim Cross


Re: [O] ob-clojure will error result when contains comment

2017-07-13 Thread numbch...@gmail.com
I run the both blocks fine in CIDER REPL, that's weird.
I have the following special settings for ob-clojure.
```elisp
(add-to-list 'org-babel-default-header-args:clojure
 '(:eval . "yes"))
(add-to-list 'org-babel-default-header-args:clojure
 '(:results . "value pp"))
(add-to-list 'org-babel-default-header-args:clojure ; for Clojure `dotimes'
etc.
 '(:show-process . "no"))
(add-to-list 'org-babel-default-header-args:clojure
 '(:noweb . "yes"))
```


[stardiviner] 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 Thu, Jul 13, 2017 at 4:48 PM, Tim Cross  wrote:

>
> I think there is something wrong with your environment and your second
> block is not legal code. If you run your second block directly in a
> clojure repl, you will get the same errors, which means it isn't an org
> issue.
>
> Executing your examples with org from master branch I get
>
> #+BEGIN_SRC clojure
> (+ 1 1) ;=> 2
> #+END_SRC
>
> #+RESULTS:
> : 2
>
> #+BEGIN_SRC clojure :results value
> (def sum1 #(reduce + %))
> (def avg1 #(/ (sum %) (count %)))
>
> (defn stats
>   [numbers]
>   (map #(% numbers) [sum1 count avg1]))
>
> (stats [3 4 10])
>
> (stats [80 1 44 13 6])
>
> #+END_SRC
>
> #+RESULTS:
> : #'user/sum1#'user/statsclass clojure.lang.Compiler$CompilerExceptionclass
> java.lang.IllegalStateExceptionclass java.lang.IllegalStateExceptionclass
> clojure.lang.Compiler$CompilerExceptionclass 
> java.lang.IllegalStateExceptionclass
> java.lang.IllegalStateExceptionCompilerException
> java.lang.RuntimeException: Unable to resolve symbol: sum in this context,
> compiling:(/tmp/form-init6637865895670060372.clj:2:15)
> : IllegalStateException Attempting to call unbound fn: #'user/avg1
> clojure.lang.Var$Unbound.throwArity (Var.java:43)
> : IllegalStateException Attempting to call unbound fn: #'user/avg1
> clojure.lang.Var$Unbound.throwArity (Var.java:43)
>
> I'm not sure why the version of ob-clojure.el is not yet in the org or
> org-plus-contrib packages - Does master only become maint after major
> version releases?
>
> Note also, there appears to be an issue with most recent versions of
> cider when you do cider-jack-in and your not inside a project. The
> issues seem to relate mainly to clj-refactor, but there could be other
> problems. Again, highly recommend running your cider inside a clojure
> project.
>
> Tim
>
> numbch...@gmail.com writes:
>
> > Here is the examples:
> >
> > #+BEGIN_SRC clojure
> > (+ 1 1) ;=> 2
> > #+END_SRC
> >
> > #+RESULTS:
> > : class clojure.lang.LispReader$ReaderExceptionclass
> > java.lang.RuntimeExceptionRuntimeException EOF while reading, starting
> at
> > line 1  clojure.lang.Util.runtimeException (Util.java:221)
> >
> > #+BEGIN_SRC clojure :results value
> > (def sum1 #(reduce + %))
> > (def avg1 #(/ (sum %) (count %)))
> >
> > (defn stats
> >   [numbers]
> >   (map #(% numbers) [sum1 count avg1]))
> >
> > (stats [3 4 10])
> > ;; => (17 3 17/3)
> >
> > (stats [80 1 44 13 6])
> > ;; => (144 5 144/5)
> > #+END_SRC
> >
> > #+RESULTS:
> > : class clojure.lang.LispReader$ReaderExceptionclass
> > java.lang.RuntimeExceptionRuntimeException EOF while reading, starting
> at
> > line 1  clojure.lang.Util.runtimeException (Util.java:221)
> >
> >
> > [stardiviner] 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
>


Re: [O] ob-clojure will error result when contains comment

2017-07-13 Thread Tim Cross

I think there is something wrong with your environment and your second
block is not legal code. If you run your second block directly in a
clojure repl, you will get the same errors, which means it isn't an org issue.

Executing your examples with org from master branch I get

#+BEGIN_SRC clojure
(+ 1 1) ;=> 2
#+END_SRC

#+RESULTS:
: 2

#+BEGIN_SRC clojure :results value
(def sum1 #(reduce + %))
(def avg1 #(/ (sum %) (count %)))

(defn stats
  [numbers]
  (map #(% numbers) [sum1 count avg1]))

(stats [3 4 10])

(stats [80 1 44 13 6])

#+END_SRC

#+RESULTS:
: #'user/sum1#'user/statsclass clojure.lang.Compiler$CompilerExceptionclass 
java.lang.IllegalStateExceptionclass java.lang.IllegalStateExceptionclass 
clojure.lang.Compiler$CompilerExceptionclass 
java.lang.IllegalStateExceptionclass 
java.lang.IllegalStateExceptionCompilerException java.lang.RuntimeException: 
Unable to resolve symbol: sum in this context, 
compiling:(/tmp/form-init6637865895670060372.clj:2:15) 
: IllegalStateException Attempting to call unbound fn: #'user/avg1  
clojure.lang.Var$Unbound.throwArity (Var.java:43)
: IllegalStateException Attempting to call unbound fn: #'user/avg1  
clojure.lang.Var$Unbound.throwArity (Var.java:43)

I'm not sure why the version of ob-clojure.el is not yet in the org or
org-plus-contrib packages - Does master only become maint after major
version releases?

Note also, there appears to be an issue with most recent versions of
cider when you do cider-jack-in and your not inside a project. The
issues seem to relate mainly to clj-refactor, but there could be other
problems. Again, highly recommend running your cider inside a clojure
project.

Tim

numbch...@gmail.com writes:

> Here is the examples:
>
> #+BEGIN_SRC clojure
> (+ 1 1) ;=> 2
> #+END_SRC
>
> #+RESULTS:
> : class clojure.lang.LispReader$ReaderExceptionclass
> java.lang.RuntimeExceptionRuntimeException EOF while reading, starting at
> line 1  clojure.lang.Util.runtimeException (Util.java:221)
>
> #+BEGIN_SRC clojure :results value
> (def sum1 #(reduce + %))
> (def avg1 #(/ (sum %) (count %)))
>
> (defn stats
>   [numbers]
>   (map #(% numbers) [sum1 count avg1]))
>
> (stats [3 4 10])
> ;; => (17 3 17/3)
>
> (stats [80 1 44 13 6])
> ;; => (144 5 144/5)
> #+END_SRC
>
> #+RESULTS:
> : class clojure.lang.LispReader$ReaderExceptionclass
> java.lang.RuntimeExceptionRuntimeException EOF while reading, starting at
> line 1  clojure.lang.Util.runtimeException (Util.java:221)
>
>
> [stardiviner] 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



Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-20 Thread numbch...@gmail.com
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  "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] 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, numbch...@gmail.com 
wrote:

> I see, thanks very much.
>
> [stardiviner] 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  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
>>
>> numbch...@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  "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])
>> > ```
>> >
>> > 

Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-17 Thread numbch...@gmail.com
I see, thanks very much.

[stardiviner] 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  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
>
> numbch...@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  "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--
> >   

Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-17 Thread Tim Cross

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

numbch...@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  "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
>  

Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-17 Thread numbch...@gmail.com
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  "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  "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] 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, numbch...@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  "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
>

Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-17 Thread numbch...@gmail.com
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  "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  

Re: [O] ob-clojure evaluate error when Org-mode buffer has ns clojure code

2017-06-16 Thread Tim Cross

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

numbch...@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  "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] 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



Re: [O] ob-clojure broken

2017-03-04 Thread Tim Cross
thanks. There is a later message to the list where I attached the patch.

tim


On 4 March 2017 at 23:04, numbch...@gmail.com  wrote:

> I already applied the patch at here: https://emacs.
> stackexchange.com/questions/30857/clojure-code-evaluation-
> in-org-mode-produces-no-output
>
>
> [stardiviner] 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 Thu, Mar 2, 2017 at 7:01 AM, Tim Cross  wrote:
>
>> With current 9.0.5 org-plus-contrib package, ob-clojure is broken and
>> trying to evaluate clojure source blocks just gives a code block produces
>> no output message.
>>
>> The problem is in the org-babel-execute:clojure function. This function
>> has the following bit of code
>>
>> (setq result
>>(nrepl-dict-get
>> (nrepl-sync-request:eval
>>  expanded (cider-current-connection) (cider-current-session))
>> (if (or (member "output" result-params)
>> (member "pp" result-params))
>> "out"
>>   "value")))
>>
>> The problem is in the call to nrepl-sync-request:eval. The documentation
>> states for this function
>>
>> (nrepl-sync-request:eval INPUT CONNECTION  NS)
>>
>> Send the INPUT to the nREPL server synchronously. The request is
>> dispatched via CONNECTION. If NS is non-nil, include it in the request.
>> Note the last optional argument NS. This is supposed to be a clojure
>> namespace. However, the org-babel-execute:clojure function is calling this
>> function with the output from cider-current-session, which returns a unique
>> ID representing the current session. As a result, the call is returning a
>> data structure with an error and no output (perhaps some error handling is
>> required). The returned result is
>>
>> (dict status (namespace-not-found done error done state state) id 17
>> session 43e9fd6c-82ed-49fe-9624-0cfc6f56f8b1 changed-namespaces (dict)
>> repl-type cljclj)
>>
>> Note the namespace-not-found
>>
>> Either the argument should be a call to (cider-current-ns) or perhaps it
>> should just be left out as I don't see how you can pass the namespace as
>> part of the block evaluation.
>>
>>
>> --
>> regards,
>>
>> Tim
>>
>> --
>> Tim Cross
>>
>>
>


-- 
regards,

Tim

--
Tim Cross


Re: [O] ob-clojure broken

2017-03-04 Thread numbch...@gmail.com
I already applied the patch at here:
https://emacs.stackexchange.com/questions/30857/clojure-code-evaluation-in-org-mode-produces-no-output


[stardiviner] 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 Thu, Mar 2, 2017 at 7:01 AM, Tim Cross  wrote:

> With current 9.0.5 org-plus-contrib package, ob-clojure is broken and
> trying to evaluate clojure source blocks just gives a code block produces
> no output message.
>
> The problem is in the org-babel-execute:clojure function. This function
> has the following bit of code
>
> (setq result
>(nrepl-dict-get
> (nrepl-sync-request:eval
>  expanded (cider-current-connection) (cider-current-session))
> (if (or (member "output" result-params)
> (member "pp" result-params))
> "out"
>   "value")))
>
> The problem is in the call to nrepl-sync-request:eval. The documentation
> states for this function
>
> (nrepl-sync-request:eval INPUT CONNECTION  NS)
>
> Send the INPUT to the nREPL server synchronously. The request is
> dispatched via CONNECTION. If NS is non-nil, include it in the request.
> Note the last optional argument NS. This is supposed to be a clojure
> namespace. However, the org-babel-execute:clojure function is calling this
> function with the output from cider-current-session, which returns a unique
> ID representing the current session. As a result, the call is returning a
> data structure with an error and no output (perhaps some error handling is
> required). The returned result is
>
> (dict status (namespace-not-found done error done state state) id 17
> session 43e9fd6c-82ed-49fe-9624-0cfc6f56f8b1 changed-namespaces (dict)
> repl-type cljclj)
>
> Note the namespace-not-found
>
> Either the argument should be a call to (cider-current-ns) or perhaps it
> should just be left out as I don't see how you can pass the namespace as
> part of the block evaluation.
>
>
> --
> regards,
>
> Tim
>
> --
> Tim Cross
>
>


Re: [O] ob-clojure?

2016-09-29 Thread Frederick Giasson

Hi Lawrence,

Is there an ob-clojure in elpa? If not should I use this 
?


You may be interested in this version:

http://fgiasson.com/blog/index.php/2016/06/16/improving-org-babel-clojure/

I didn't find the time to push into the Org-mod update pipeline, but I 
will do so soon (hopefully). In mean time all the code is there.



Thanks,

Fred



Re: [O] ob-clojure?

2016-09-19 Thread Thomas S. Dye
Aloha Lawrence,

Lawrence Bottorff writes:

> Is there an ob-clojure in elpa? If not should I use this
> ?
>
> LB

Is the ob-clojure that comes with Org mode unsuitable?

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Frederick Giasson

Hi,


Yes, you are. There is a "go to the topic" action on the left panel.
Anyway, there is not much to see, just some pointers to start
a discussion.


Haa great thanks, see it now :)

Let me revise a few things, suggest another patch, and then will start 
to think about these things.


Thanks,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Nicolas Goaziou
Frederick Giasson  writes:

> Humm, from the page you provided, I don't see any threads, but just
> the initial message, am I looking at the right thing?

Yes, you are. There is a "go to the topic" action on the left panel.
Anyway, there is not much to see, just some pointers to start
a discussion.

Regards,



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Frederick Giasson

Hi Nicolas,


However, I am not sure neither how generic such a solution could be,
and what would still be required to implement in each OB plugin. My
(very little) experience so far is the Python prototype that John
wrote, and then my analysis of the Clojure OB plugin. As I was
explaining in this blog post, things are quite different between the
two. In Python, it appears that one has to run a sub-process, in
Clojure this is not necessary since we benefit the nREPL that handle
that.

The link I gave is a first approximation of the generic behaviour.
Basically, we could spawn a new Emacs process which could then
evaluation the block synchronously.


Ok good.


One difficulty is to grab the "closure" of the block. Another one is to
collect and insert the results back into the buffer without being
disruptive. The thread above gave hints about that second point.


Humm, from the page you provided, I don't see any threads, but just the 
initial message, am I looking at the right thing?


Thanks,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Nicolas Goaziou
Hello,

Frederick Giasson  writes:

> However, I am not sure neither how generic such a solution could be,
> and what would still be required to implement in each OB plugin. My
> (very little) experience so far is the Python prototype that John
> wrote, and then my analysis of the Clojure OB plugin. As I was
> explaining in this blog post, things are quite different between the
> two. In Python, it appears that one has to run a sub-process, in
> Clojure this is not necessary since we benefit the nREPL that handle
> that.

The link I gave is a first approximation of the generic behaviour.
Basically, we could spawn a new Emacs process which could then
evaluation the block synchronously.

One difficulty is to grab the "closure" of the block. Another one is to
collect and insert the results back into the buffer without being
disruptive. The thread above gave hints about that second point.

Regards,

-- 
Nicolas Goaziou



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Frederick Giasson

Hi Nicolas,


Here is a blog post that explains the changes I did. I still have one
improvement to do (but don't how it could be done or even if it can be
done) which is explained at the end of the post:

http://fgiasson.com/blog/index.php/2016/04/05/using-clojure-in-org-mode-and-implementing-asynchronous-processing/

Thanks for your help, it is now working the way I need it to.

This looks interesting. Thank you for sharing your result.

Org Babel would benefit from a generic asynchronous execution mechanism.
See for example .


Indeed, it would be interesting to generalize such a generic mechanism 
directly in Babel, and not in each OB plugins.


However, I am not sure neither how generic such a solution could be, and 
what would still be required to implement in each OB plugin. My (very 
little) experience so far is the Python prototype that John wrote, and 
then my analysis of the Clojure OB plugin. As I was explaining in this 
blog post, things are quite different between the two. In Python, it 
appears that one has to run a sub-process, in Clojure this is not 
necessary since we benefit the nREPL that handle that.


So far, the best idea about how to present async process I think is what 
John was proposing with the new window. Otherwise I still wonder about 
having a real background process for this thing to run such that one can 
continue to write things in the Org buffer while a code block is running 
in background. But as I explained, I will have to seriously look into 
Elisp in order to assess the full scope of such a task.



So, if anyone feels like discussing the details of an implementation of
such a thing, please chime in.


So far this is the only thing I have to say about that. In mean time I 
will fix my other patch, and then I will submit another one for this 
async feature (which will probably require much more review from your part).



Thanks,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-06 Thread Nicolas Goaziou
Hello,

Frederick Giasson  writes:

> Here is a blog post that explains the changes I did. I still have one
> improvement to do (but don't how it could be done or even if it can be
> done) which is explained at the end of the post:
>
> http://fgiasson.com/blog/index.php/2016/04/05/using-clojure-in-org-mode-and-implementing-asynchronous-processing/
>
> Thanks for your help, it is now working the way I need it to.

This looks interesting. Thank you for sharing your result.

Org Babel would benefit from a generic asynchronous execution mechanism.
See for example .

So, if anyone feels like discussing the details of an implementation of
such a thing, please chime in.

Regards,

-- 
Nicolas Goaziou



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-04-05 Thread Frederick Giasson

Hi John,

Here is a blog post that explains the changes I did. I still have one 
improvement to do (but don't how it could be done or even if it can be 
done) which is explained at the end of the post:


http://fgiasson.com/blog/index.php/2016/04/05/using-clojure-in-org-mode-and-implementing-asynchronous-processing/

Thanks for your help, it is now working the way I need it to.


Take care,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Frederick Giasson

Hi Jon,


You can see a commented out version for shell blocks here:
https://github.com/jkitchin/jmax/blob/master/jmax-org.el#L936

It looks like I just redefined the org-babel-execute:sh function after
it was loaded. That may not be recommended good practice, but it works
;)

I am not sure why it is commented out, maybe because I don't use it alot
and its not well tested.

You could always bind your own key sequence instead of C-c C-c.



Yes this is right, probably better/easier/cleaner


I am almost here with my code. In fact, it is quite different than yours 
since the nrepl does async communication. So far, I am really just using 
the Buffer in a new window idea from your code since I don't need to do 
anything with external files.


Will keep you updated!

Thanks,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread John Kitchin
a
Frederick Giasson writes:

> Hi John,
>
>> you should rename it org-babel-async-execute:clojure, and adapt it to
>> run clojure.
>
> Yes
>
>> I wrote the function in the org-file that is that post, and executed the
>> code block (C-c C-c) which "registers" the function for that instance of
>> emacs.
>
> I am not sure I understand here. Once you execute the elisp block with
> that function, the function becomes defined for that instance. But when
> you execute your other block, the example python block using C-c C-c,
> how does org-mode knows to use "org-babel-async-execute:python" instead
> of "org-babel-execute:python"??
>
> You put the cursor in the block, and then call it using M-x?

Right, with the cursor in the block type M-x org-babel-async-execute:clojure
>
>> Later you could put it in an init file that is loaded when Emacs starts.
>>
>> and use M-x to call it. Once I added an :async option to the header args
>> to make C-c C-c execute it, but until it works the way you want with M-x
>> that is just convenience ;)
>
> Yes, this is that :async option that would be great and necessary once
> it works using M-x :)
>
> How can this be done? (Is there an extension mechanism in org-mode for
> that, or it needs to hack the core code?)

You can see a commented out version for shell blocks here:
https://github.com/jkitchin/jmax/blob/master/jmax-org.el#L936

It looks like I just redefined the org-babel-execute:sh function after
it was loaded. That may not be recommended good practice, but it works
;)

I am not sure why it is commented out, maybe because I don't use it alot
and its not well tested.

You could always bind your own key sequence instead of C-c C-c.


>
> Thanks,
>
>
> Fred


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Frederick Giasson

Hi John,


you should rename it org-babel-async-execute:clojure, and adapt it to
run clojure.


Yes


I wrote the function in the org-file that is that post, and executed the
code block (C-c C-c) which "registers" the function for that instance of
emacs.


I am not sure I understand here. Once you execute the elisp block with 
that function, the function becomes defined for that instance. But when 
you execute your other block, the example python block using C-c C-c, 
how does org-mode knows to use "org-babel-async-execute:python" instead 
of "org-babel-execute:python"??


You put the cursor in the block, and then call it using M-x?


Later you could put it in an init file that is loaded when Emacs starts.

and use M-x to call it. Once I added an :async option to the header args
to make C-c C-c execute it, but until it works the way you want with M-x
that is just convenience ;)


Yes, this is that :async option that would be great and necessary once 
it works using M-x :)


How can this be done? (Is there an extension mechanism in org-mode for 
that, or it needs to hack the core code?)


Thanks,


Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread John Kitchin
you should rename it org-babel-async-execute:clojure, and adapt it to
run clojure.

I wrote the function in the org-file that is that post, and executed the
code block (C-c C-c) which "registers" the function for that instance of
emacs. Later you could put it in an init file that is loaded when Emacs starts.

and use M-x to call it. Once I added an :async option to the header args
to make C-c C-c execute it, but until it works the way you want with M-x
that is just convenience ;)

Frederick Giasson writes:

> Hi John!
>
> Interesting approach :)
>
> I am really new with org-mode, but I will try to adapt for ob-clojure.el.
>
> One question: this function "org-babel-async-execute:python", where
> should I register it? I guess it should replace "org-babel-execute:python"?
>
> Thanks for this precision will work on that once I know how to plug that
> into org-mode to start testing the code I will adapt.
>
> Thanks,
>
> Fred
>
>
>> This might not be totally true.
>>
>> In this post I use a few different asynchronous approaches to running
>> Python that do something like what you want, perhaps especially the last
>> bit of the post.
>>
>> http://kitchingroup.cheme.cmu.edu/blog/2015/11/20/Asynchronously-running-python-blocks-in-org-mode/
>>
>> Maybe you could adapt it for clojure.
>>
>> Frederick Giasson writes:
>>
>>> Hi Eric,
>>>
> Note: I am not sure if this is something related to Org-mode, or
> ob-clojure or Cider.
 None of these directly.  It's Emacs, basically: it has very minimal
 support for threading so the whole process (Emacs) is waiting for the
 sub-process (Clojure) to finish before doing anything else.
>>>
>>> Ok good, thanks for confirming!
>>>
>>> Take care,
>>>
>>> Fred
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Frederick Giasson

Hi John!

Interesting approach :)

I am really new with org-mode, but I will try to adapt for ob-clojure.el.

One question: this function "org-babel-async-execute:python", where 
should I register it? I guess it should replace "org-babel-execute:python"?


Thanks for this precision will work on that once I know how to plug that 
into org-mode to start testing the code I will adapt.


Thanks,

Fred



This might not be totally true.

In this post I use a few different asynchronous approaches to running
Python that do something like what you want, perhaps especially the last
bit of the post.

http://kitchingroup.cheme.cmu.edu/blog/2015/11/20/Asynchronously-running-python-blocks-in-org-mode/

Maybe you could adapt it for clojure.

Frederick Giasson writes:


Hi Eric,


Note: I am not sure if this is something related to Org-mode, or
ob-clojure or Cider.

None of these directly.  It's Emacs, basically: it has very minimal
support for threading so the whole process (Emacs) is waiting for the
sub-process (Clojure) to finish before doing anything else.


Ok good, thanks for confirming!

Take care,

Fred


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu






Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Eric S Fraga
On Wednesday, 30 Mar 2016 at 08:30, John Kitchin wrote:
> This might not be totally true.

Which is why I said "minimal support" ;-)

But you are correct: there are mechanisms for asynchronous threading in
Emacs.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.92.1, Org release_8.3.4-668-g809a83



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread John Kitchin
This might not be totally true.

In this post I use a few different asynchronous approaches to running
Python that do something like what you want, perhaps especially the last
bit of the post.

http://kitchingroup.cheme.cmu.edu/blog/2015/11/20/Asynchronously-running-python-blocks-in-org-mode/

Maybe you could adapt it for clojure.

Frederick Giasson writes:

> Hi Eric,
>
>>> Note: I am not sure if this is something related to Org-mode, or
>>> ob-clojure or Cider.
>> None of these directly.  It's Emacs, basically: it has very minimal
>> support for threading so the whole process (Emacs) is waiting for the
>> sub-process (Clojure) to finish before doing anything else.
>
>
> Ok good, thanks for confirming!
>
> Take care,
>
> Fred


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Frederick Giasson

Hi Eric,


Note: I am not sure if this is something related to Org-mode, or
ob-clojure or Cider.

None of these directly.  It's Emacs, basically: it has very minimal
support for threading so the whole process (Emacs) is waiting for the
sub-process (Clojure) to finish before doing anything else.



Ok good, thanks for confirming!

Take care,

Fred



Re: [O] ob-clojure: possible to display results as soon as something is written to STDOUT?

2016-03-30 Thread Eric S Fraga
On Tuesday, 29 Mar 2016 at 13:44, Frederick Giasson wrote:

[...]

> Note: I am not sure if this is something related to Org-mode, or
> ob-clojure or Cider.

None of these directly.  It's Emacs, basically: it has very minimal
support for threading so the whole process (Emacs) is waiting for the
sub-process (Clojure) to finish before doing anything else.
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.92.1, Org release_8.3.4-668-g809a83



Re: [O] ob-clojure: ':results pp' parses the output as a string value

2014-04-14 Thread Oleh
Hi Phil,

Could you test my last commit? Your case should be working now.

regards,
Oleh



Re: [O] ob-clojure: ':results pp' parses the output as a string value

2014-04-14 Thread Phill Wolf
Yes, perfect!


On Mon, Apr 14, 2014 at 6:35 AM, Oleh ohwoeo...@gmail.com wrote:

 Hi Phil,

 Could you test my last commit? Your case should be working now.

 regards,
 Oleh



Re: [O] ob-clojure: presentation of map structures?

2014-02-02 Thread Soapy Smith
On Sun, 2014-02-02 at 01:42 -0500, Phill Wolf wrote:

 Floundering among the options, I tried :results value pp.  It yielded
 this:
 
 : {\Pluto\ 5,\n \Plattsburgh\ 4,\n \Philadelphia\ 3,\n
 \Sankt-Peterburg\ 2,\n \Paris\ 1,\n \Peru\ 0}\n
 
 
 pprint's good intentions are evident, but they collided with a
 superior force.

There was a discussion of this at the Clojure google group:
https://groups.google.com/d/msg/clojure/gthjNWfAWKo/aKwuqh2qx68J

The tabularization problem was resolved, but the pp of the map behavior
is not changed.  I tried a few permutations of :results options, and did
not get close to the Clojure pprint function.

The org manual says the pp option is This
option currently supports Emacs Lisp, Python, and Ruby. E.g., :results
value pp.

Regards,
Greg





Re: [O] ob-clojure: presentation of map structures?

2014-02-01 Thread Eric Schulte
Phill Wolf phill.w...@gmail.com writes:

 How may I use an Org document to illustrate Clojure src blocks that produce
 Clojure data structures -- particularly maps -- as pretty-printed text?  I
 think I am using Org master in Emacs 24.3.

 #+BEGIN_SRC clojure :results value what options?
 (zipmap
   [Peru Paris Sankt-Peterburg Philadelphia Plattsburgh Pluto]
   (range))
 #+END_SRC

 By the way, Clojure pprint makes the value into the following, which would
 be very respectable (with the addition of : org markup) as a result block
 in the Org buffer:

 {Pluto 5,
  Plattsburgh 4,
  Philadelphia 3,
  Putingrad 2,
  Paris 1,
  Peru 0}

 Floundering among the options, I tried :results value pp.  It yielded this:

 : {\Pluto\ 5,\n \Plattsburgh\ 4,\n \Philadelphia\ 3,\n
 \Sankt-Peterburg\ 2,\n \Paris\ 1,\n \Peru\ 0}\n

 pprint's good intentions are evident, but they collided with a superior
 force.

Maybe try :results pp org.

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