all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
@ 2018-11-30  8:46 stardiviner
  2018-11-30 21:25 ` Tim Cross
  2019-01-10  1:47 ` stardiviner
  0 siblings, 2 replies; 10+ messages in thread
From: stardiviner @ 2018-11-30  8:46 UTC (permalink / raw)
  To: org-mode


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.

--
[ 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

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2018-11-30  8:46 ob-clojure should not tangle with inserting (ns ..) line when no :ns specified stardiviner
@ 2018-11-30 21:25 ` Tim Cross
  2018-12-03  6:25   ` stardiviner
  2019-01-10  1:47 ` stardiviner
  1 sibling, 1 reply; 10+ messages in thread
From: Tim Cross @ 2018-11-30 21:25 UTC (permalink / raw)
  To: numbchild; +Cc: org-mode


stardiviner <numbchild@gmail.com> 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

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2018-11-30 21:25 ` Tim Cross
@ 2018-12-03  6:25   ` stardiviner
  2018-12-04 21:22     ` Tim Cross
  0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2018-12-03  6:25 UTC (permalink / raw)
  To: Tim Cross; +Cc: org-mode


Tim Cross <theophilusx@gmail.com> 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

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2018-12-03  6:25   ` stardiviner
@ 2018-12-04 21:22     ` Tim Cross
  2018-12-05  9:04       ` stardiviner
  0 siblings, 1 reply; 10+ messages in thread
From: Tim Cross @ 2018-12-04 21:22 UTC (permalink / raw)
  To: numbchild; +Cc: org-mode


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 <numbchild@gmail.com> writes:

> Tim Cross <theophilusx@gmail.com> 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

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2018-12-04 21:22     ` Tim Cross
@ 2018-12-05  9:04       ` stardiviner
  0 siblings, 0 replies; 10+ messages in thread
From: stardiviner @ 2018-12-05  9:04 UTC (permalink / raw)
  To: Tim Cross; +Cc: org-mode


Tim Cross <theophilusx@gmail.com> 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

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2018-11-30  8:46 ob-clojure should not tangle with inserting (ns ..) line when no :ns specified stardiviner
  2018-11-30 21:25 ` Tim Cross
@ 2019-01-10  1:47 ` stardiviner
  2019-01-14  5:52   ` stardiviner
  1 sibling, 1 reply; 10+ messages in thread
From: stardiviner @ 2019-01-10  1:47 UTC (permalink / raw)
  To: org-mode

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


stardiviner <numbchild@gmail.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-clojure.el-Don-t-tangle-with-auto-prepend-ns.patch --]
[-- Type: text/x-patch, Size: 3154 bytes --]

From 749e85a30ca6226c4b3aaef85ae0d72b51d6018e Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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


[-- Attachment #3: Type: text/plain, Size: 255 bytes --]



-- 
[ 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
      

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

* Re: ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2019-01-10  1:47 ` stardiviner
@ 2019-01-14  5:52   ` stardiviner
  2019-01-21  0:39     ` [PATCH] " stardiviner
  0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2019-01-14  5:52 UTC (permalink / raw)
  To: org-mode; +Cc: Nicolas Goaziou

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


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-clojure.el-Don-t-tangle-with-auto-prepend-ns.patch --]
[-- Type: text/x-patch, Size: 4052 bytes --]

From 8a64ccf659afcbd510e69eaa4ac175946f1ae311 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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
index f917ca4cc..a5391dcb3 100644
--- a/testing/lisp/test-ob-clojure.el
+++ b/testing/lisp/test-ob-clojure.el
@@ -71,6 +71,20 @@
     (should (string=
 	     ": 1"
 	     (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
+(ert-deftest ob-clojure/tangle-without-ns ()
+  (org-test-with-temp-text
+   "#+begin_src clojure :tangle /tmp/test.clj
+(print 1)
+#+end_src"
+   (org-babel-next-src-block)
+   (org-babel-tangle)
+   (should
+    (string=
+     "(print 1)
+"
+     (with-temp-buffer
+       (insert-file-contents "/tmp/test.clj")
+       (buffer-substring-no-properties (point-min) (point-max)))))))
 
 (provide 'test-ob-clojure)
 
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 247 bytes --]



--
[ 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

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

* [PATCH] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2019-01-14  5:52   ` stardiviner
@ 2019-01-21  0:39     ` stardiviner
  2019-01-21 20:19       ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2019-01-21  0:39 UTC (permalink / raw)
  To: org-mode

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

After few days later, I re-run "make test", it's fine now.

6 unexpected results:
   FAILED  ob-D/inhomogeneous_table
   FAILED  ob-D/list-list-var
   FAILED  ob-D/list-var
   FAILED  ob-D/vector-var
   FAILED  test-org-clock/clocktable/lang
   FAILED  test-org-colview/columns-width

Because few days passed, make sure the patch is the latest version. I
attached my patch again.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-clojure.el-Don-t-tangle-with-auto-prepend-ns.patch --]
[-- Type: text/x-patch, Size: 4052 bytes --]

From 8a64ccf659afcbd510e69eaa4ac175946f1ae311 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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
index f917ca4cc..a5391dcb3 100644
--- a/testing/lisp/test-ob-clojure.el
+++ b/testing/lisp/test-ob-clojure.el
@@ -71,6 +71,20 @@
     (should (string=
 	     ": 1"
 	     (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
+(ert-deftest ob-clojure/tangle-without-ns ()
+  (org-test-with-temp-text
+   "#+begin_src clojure :tangle /tmp/test.clj
+(print 1)
+#+end_src"
+   (org-babel-next-src-block)
+   (org-babel-tangle)
+   (should
+    (string=
+     "(print 1)
+"
+     (with-temp-buffer
+       (insert-file-contents "/tmp/test.clj")
+       (buffer-substring-no-properties (point-min) (point-max)))))))
 
 (provide 'test-ob-clojure)
 
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 255 bytes --]



-- 
[ 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
      

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

* Re: [PATCH] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2019-01-21  0:39     ` [PATCH] " stardiviner
@ 2019-01-21 20:19       ` Nicolas Goaziou
  2019-01-22  7:57         ` stardiviner
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2019-01-21 20:19 UTC (permalink / raw)
  To: stardiviner; +Cc: org-mode

Hello,

stardiviner <numbchild@gmail.com> writes:

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

Applied, with tiny changes. Thank you.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] ob-clojure should not tangle with inserting (ns ..) line when no :ns specified.
  2019-01-21 20:19       ` Nicolas Goaziou
@ 2019-01-22  7:57         ` stardiviner
  0 siblings, 0 replies; 10+ messages in thread
From: stardiviner @ 2019-01-22  7:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> From 8a64ccf659afcbd510e69eaa4ac175946f1ae311 Mon Sep 17 00:00:00 2001
>> From: stardiviner <numbchild@gmail.com>
>> Date: Thu, 10 Jan 2019 09:34:39 +0800
>> Subject: [PATCH] lisp/ob-clojure.el: Don't tangle with auto prepend ns
>>  statement
>
> Applied, with tiny changes. Thank you.

Thanks as always, Nicolas.

>
> 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
      

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

end of thread, other threads:[~2019-01-22  7:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-30  8:46 ob-clojure should not tangle with inserting (ns ..) line when no :ns specified stardiviner
2018-11-30 21:25 ` Tim Cross
2018-12-03  6:25   ` stardiviner
2018-12-04 21:22     ` Tim Cross
2018-12-05  9:04       ` stardiviner
2019-01-10  1:47 ` stardiviner
2019-01-14  5:52   ` stardiviner
2019-01-21  0:39     ` [PATCH] " stardiviner
2019-01-21 20:19       ` Nicolas Goaziou
2019-01-22  7:57         ` stardiviner

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.