* ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
@ 2024-10-15 17:43 Anoop GR
2024-10-15 17:51 ` Anoop GR
2024-10-16 19:49 ` Ihor Radchenko
0 siblings, 2 replies; 10+ messages in thread
From: Anoop GR @ 2024-10-15 17:43 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 920 bytes --]
Comments in org babel clojure blocks are not tangled out.
Let us take an example org file with the following contents:-
This org file contains only two source blocks and a total of ten lines.
> #+begin_src clojure :noweb-ref "Define a constant"
>
(def e 2.72)
;;This is a comment on a line of its own
> (def pi 3.14) ;;This is a comment not on a line of its own
> #+end_src
The following block will be tangled
> #+begin_src clojure :noweb yes :tangle ./output.clj
> <<Define a constant>>
> #+end_src
When I tangle the above file, the contents of the output.clj file are:-
> (def e 2.72)
> (def pi 3.14) ;;This is a comment not on a line of its own
*The comment that was on a line of its own is missing from the tangled
output.*
Was able to reproduce on both emacs 29.3.50 and 29.4 on Ubuntu 22.04 LTS
Both were started using *emacs -Q* and then evaluating *(require
'ob-clojure)* as the only line of config.
[-- Attachment #2: Type: text/html, Size: 1980 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-15 17:43 ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks Anoop GR
@ 2024-10-15 17:51 ` Anoop GR
2024-10-15 17:52 ` Anoop GR
2024-10-16 19:49 ` Ihor Radchenko
1 sibling, 1 reply; 10+ messages in thread
From: Anoop GR @ 2024-10-15 17:51 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1471 bytes --]
The contents of the org file were
---
This file contains only two source blocks
#+begin_src clojure :noweb-ref "Define a constant"
(def e 2.72)
;;This is a comment on a line of its own
(def pi 3.14) ;;This is a comment not on a line of its own
#+end_src
The following block will be tangled
#+begin_src clojure :noweb yes :tangle output.clj
<<Define a constant>>
#+end_src
---
On Tue, Oct 15, 2024 at 11:13 PM Anoop GR <anoopemacs@gmail.com> wrote:
> Comments in org babel clojure blocks are not tangled out.
>
> Let us take an example org file with the following contents:-
>
> This org file contains only two source blocks and a total of ten lines.
>> #+begin_src clojure :noweb-ref "Define a constant"
>>
> (def e 2.72)
>
> ;;This is a comment on a line of its own
>> (def pi 3.14) ;;This is a comment not on a line of its own
>> #+end_src
>
> The following block will be tangled
>> #+begin_src clojure :noweb yes :tangle ./output.clj
>> <<Define a constant>>
>> #+end_src
>
>
> When I tangle the above file, the contents of the output.clj file are:-
>
>> (def e 2.72)
>
>
>> (def pi 3.14) ;;This is a comment not on a line of its own
>
>
> *The comment that was on a line of its own is missing from the tangled
> output.*
>
> Was able to reproduce on both emacs 29.3.50 and 29.4 on Ubuntu 22.04 LTS
> Both were started using *emacs -Q* and then evaluating *(require
> 'ob-clojure)* as the only line of config.
>
[-- Attachment #2: Type: text/html, Size: 2799 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-15 17:51 ` Anoop GR
@ 2024-10-15 17:52 ` Anoop GR
2024-10-15 17:53 ` Anoop GR
0 siblings, 1 reply; 10+ messages in thread
From: Anoop GR @ 2024-10-15 17:52 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]
The contents of the tangled output.clj file were:-
---
(def e 2.72)
(def pi 3.14) ;;This is a comment not on a line of its own
---
On Tue, Oct 15, 2024 at 11:21 PM Anoop GR <anoopemacs@gmail.com> wrote:
> The contents of the org file were
> ---
> This file contains only two source blocks
> #+begin_src clojure :noweb-ref "Define a constant"
> (def e 2.72)
> ;;This is a comment on a line of its own
> (def pi 3.14) ;;This is a comment not on a line of its own
> #+end_src
>
> The following block will be tangled
> #+begin_src clojure :noweb yes :tangle output.clj
> <<Define a constant>>
> #+end_src
> ---
>
> On Tue, Oct 15, 2024 at 11:13 PM Anoop GR <anoopemacs@gmail.com> wrote:
>
>> Comments in org babel clojure blocks are not tangled out.
>>
>> Let us take an example org file with the following contents:-
>>
>> This org file contains only two source blocks and a total of ten lines.
>>> #+begin_src clojure :noweb-ref "Define a constant"
>>>
>> (def e 2.72)
>>
>> ;;This is a comment on a line of its own
>>> (def pi 3.14) ;;This is a comment not on a line of its own
>>> #+end_src
>>
>> The following block will be tangled
>>> #+begin_src clojure :noweb yes :tangle ./output.clj
>>> <<Define a constant>>
>>> #+end_src
>>
>>
>> When I tangle the above file, the contents of the output.clj file are:-
>>
>>> (def e 2.72)
>>
>>
>>> (def pi 3.14) ;;This is a comment not on a line of its own
>>
>>
>> *The comment that was on a line of its own is missing from the tangled
>> output.*
>>
>> Was able to reproduce on both emacs 29.3.50 and 29.4 on Ubuntu 22.04 LTS
>> Both were started using *emacs -Q* and then evaluating *(require
>> 'ob-clojure)* as the only line of config.
>>
>
[-- Attachment #2: Type: text/html, Size: 3325 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-15 17:52 ` Anoop GR
@ 2024-10-15 17:53 ` Anoop GR
0 siblings, 0 replies; 10+ messages in thread
From: Anoop GR @ 2024-10-15 17:53 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]
We are missing the comment that was expected in the second line of the
output.
In its place, there is an empty newline.
On Tue, Oct 15, 2024 at 11:22 PM Anoop GR <anoopemacs@gmail.com> wrote:
> The contents of the tangled output.clj file were:-
> ---
> (def e 2.72)
>
> (def pi 3.14) ;;This is a comment not on a line of its own
> ---
>
> On Tue, Oct 15, 2024 at 11:21 PM Anoop GR <anoopemacs@gmail.com> wrote:
>
>> The contents of the org file were
>> ---
>> This file contains only two source blocks
>> #+begin_src clojure :noweb-ref "Define a constant"
>> (def e 2.72)
>> ;;This is a comment on a line of its own
>> (def pi 3.14) ;;This is a comment not on a line of its own
>> #+end_src
>>
>> The following block will be tangled
>> #+begin_src clojure :noweb yes :tangle output.clj
>> <<Define a constant>>
>> #+end_src
>> ---
>>
>> On Tue, Oct 15, 2024 at 11:13 PM Anoop GR <anoopemacs@gmail.com> wrote:
>>
>>> Comments in org babel clojure blocks are not tangled out.
>>>
>>> Let us take an example org file with the following contents:-
>>>
>>> This org file contains only two source blocks and a total of ten lines.
>>>> #+begin_src clojure :noweb-ref "Define a constant"
>>>>
>>> (def e 2.72)
>>>
>>> ;;This is a comment on a line of its own
>>>> (def pi 3.14) ;;This is a comment not on a line of its own
>>>> #+end_src
>>>
>>> The following block will be tangled
>>>> #+begin_src clojure :noweb yes :tangle ./output.clj
>>>> <<Define a constant>>
>>>> #+end_src
>>>
>>>
>>> When I tangle the above file, the contents of the output.clj file are:-
>>>
>>>> (def e 2.72)
>>>
>>>
>>>> (def pi 3.14) ;;This is a comment not on a line of its own
>>>
>>>
>>> *The comment that was on a line of its own is missing from the tangled
>>> output.*
>>>
>>> Was able to reproduce on both emacs 29.3.50 and 29.4 on Ubuntu 22.04 LTS
>>> Both were started using *emacs -Q* and then evaluating *(require
>>> 'ob-clojure)* as the only line of config.
>>>
>>
[-- Attachment #2: Type: text/html, Size: 3843 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-15 17:43 ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks Anoop GR
2024-10-15 17:51 ` Anoop GR
@ 2024-10-16 19:49 ` Ihor Radchenko
2024-10-17 13:42 ` Anoop GR
1 sibling, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2024-10-16 19:49 UTC (permalink / raw)
To: Anoop GR; +Cc: emacs-orgmode, Bastien Guerry
Anoop GR <anoopemacs@gmail.com> writes:
> Comments in org babel clojure blocks are not tangled out.
> ...
This seems to be intentional (commit b1f564b4b6):
In ob-clojure.el, we have:
;; Remove comments, they break (let [...] ...) bindings
(body (replace-regexp-in-string "^[ ]*;+.*$" "" body))
It seems that there is some weirdness in Clojure interaction with
comments inside let [...] clauses.
I am not familiar enough with closure to comment on this. Maybe you know
more?
CCing Bastien, the author of the commit.
I guess that we may leave the comments intact if the code block does not
have :var.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-16 19:49 ` Ihor Radchenko
@ 2024-10-17 13:42 ` Anoop GR
2024-10-17 17:59 ` Ihor Radchenko
0 siblings, 1 reply; 10+ messages in thread
From: Anoop GR @ 2024-10-17 13:42 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Bastien Guerry
[-- Attachment #1: Type: text/plain, Size: 2162 bytes --]
>
> I guess that we may leave the comments intact if the code block does not
> have :var.
>
I moved the comment stripping code in org-babel-expand-body:clojure to
follow the above idea:-
---
(defun org-babel-expand-body:clojure (body params)
"Expand BODY according to PARAMS, return the expanded body."
(let* ((vars (org-babel--get-vars params))
(backend-override (cdr (assq :backend params)))
(org-babel-clojure-backend
(cond
(backend-override (intern backend-override))
(org-babel-clojure-backend org-babel-clojure-backend)
(t (user-error "You need to customize `org-babel-clojure-backend'
or set the `:backend' header argument"))))
(ns (or (cdr (assq :ns params))
(if (eq org-babel-clojure-backend 'cider)
(or cider-buffer-ns
(let ((repl-buf (cider-current-connection)))
(and repl-buf (buffer-local-value
'cider-buffer-ns repl-buf))))
org-babel-clojure-default-ns)))
(result-params (cdr (assq :result-params params)))
(print-level nil)
(print-length nil)
(body (org-trim
(concat
;; Source block specified namespace :ns.
(and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
;; Variables binding.
(if (null vars)
(org-trim body)
(let ((body (replace-regexp-in-string "^[ ]*;+.*$" ""
body))) ; Remove comments, they break (let [...] ...) bindings
(format "(let [%s]\n%s)"
(mapconcat
(lambda (var)
(format "%S '%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)
body)))
---
Now, it no longer loses comments on tangling.
[-- Attachment #2: Type: text/html, Size: 3017 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-17 13:42 ` Anoop GR
@ 2024-10-17 17:59 ` Ihor Radchenko
2024-10-18 10:18 ` Anoop GR
0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2024-10-17 17:59 UTC (permalink / raw)
To: Anoop GR; +Cc: emacs-orgmode, Bastien Guerry
Anoop GR <anoopemacs@gmail.com> writes:
>>
>> I guess that we may leave the comments intact if the code block does not
>> have :var.
>>
>
> I moved the comment stripping code in org-babel-expand-body:clojure to
> follow the above idea:-
> ...
The code look reasonable.
Would you be interested to convert it into a patch?
See https://orgmode.org/worg/org-contribute.html
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-17 17:59 ` Ihor Radchenko
@ 2024-10-18 10:18 ` Anoop GR
2024-10-18 17:23 ` Ihor Radchenko
0 siblings, 1 reply; 10+ messages in thread
From: Anoop GR @ 2024-10-18 10:18 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Bastien Guerry
[-- Attachment #1.1: Type: text/plain, Size: 815 bytes --]
I have attached the patch file, created against the latest main branch.
On Thu, Oct 17, 2024 at 11:28 PM Ihor Radchenko <yantar92@posteo.net> wrote:
> Anoop GR <anoopemacs@gmail.com> writes:
>
> >>
> >> I guess that we may leave the comments intact if the code block does not
> >> have :var.
> >>
> >
> > I moved the comment stripping code in org-babel-expand-body:clojure to
> > follow the above idea:-
> > ...
>
> The code look reasonable.
> Would you be interested to convert it into a patch?
> See https://orgmode.org/worg/org-contribute.html
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>
[-- Attachment #1.2: Type: text/html, Size: 1567 bytes --]
[-- Attachment #2: 0001-ob-clojure.el-Fix-comments-getting-deleted-on-tangli.patch --]
[-- Type: text/x-patch, Size: 1769 bytes --]
From c5d656c10c78a1738d3daf50a0dc0a46ebf3fd3e Mon Sep 17 00:00:00 2001
From: Anoop G R <anoopemacs@gmail.com>
Date: Fri, 18 Oct 2024 15:30:54 +0530
Subject: [PATCH] ob-clojure.el: Fix comments getting deleted on tangling of
clojure source blocks
* lisp/ob-clojure.el (org-babel-expand-body:clojure): Leave the
comments intact if the code block does not have :var.
Reported-by: "Anoop G R" <anoopemacs@gmail.com>
Link: https://list.orgmode.org/874j5azk2p.fsf@localhost/T/#t
TINYCHANGE
---
lisp/ob-clojure.el | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 98a66d1..fdb0a75 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -155,21 +155,21 @@ or set the `:backend' header argument"))))
(result-params (cdr (assq :result-params params)))
(print-level nil)
(print-length nil)
- ;; Remove comments, they break (let [...] ...) bindings
- (body (replace-regexp-in-string "^[ ]*;+.*$" "" body))
(body (org-trim
(concat
;; Source block specified namespace :ns.
(and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
;; Variables binding.
(if (null vars) (org-trim body)
- (format "(let [%s]\n%s)"
+ ;; Remove comments, they break (let [...] ...) bindings
+ (let ((body (replace-regexp-in-string "^[ ]*;+.*$" "" body)))
+ (format "(let [%s]\n%s)"
(mapconcat
(lambda (var)
(format "%S '%S" (car var) (cdr var)))
vars
"\n ")
- body))))))
+ body)))))))
;; If the result param is set to "output" we don't have to do
;; anything special and just let the backend handle everything
(if (member "output" result-params)
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-18 10:18 ` Anoop GR
@ 2024-10-18 17:23 ` Ihor Radchenko
2024-10-18 20:16 ` Anoop GR
0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2024-10-18 17:23 UTC (permalink / raw)
To: Anoop GR; +Cc: emacs-orgmode, Bastien Guerry
Anoop GR <anoopemacs@gmail.com> writes:
> I have attached the patch file, created against the latest main branch.
Thanks!
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=23eb697df6
Fixed.
I also added you to the contributor list
https://git.sr.ht/~bzg/worg/commit/c5020487
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks
2024-10-18 17:23 ` Ihor Radchenko
@ 2024-10-18 20:16 ` Anoop GR
0 siblings, 0 replies; 10+ messages in thread
From: Anoop GR @ 2024-10-18 20:16 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Bastien Guerry
[-- Attachment #1: Type: text/plain, Size: 731 bytes --]
Thanks a lot Ihor for the quick response and guidance :-)
On Fri, Oct 18, 2024 at 10:51 PM Ihor Radchenko <yantar92@posteo.net> wrote:
> Anoop GR <anoopemacs@gmail.com> writes:
>
> > I have attached the patch file, created against the latest main branch.
>
> Thanks!
> Applied, onto main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=23eb697df6
> Fixed.
>
> I also added you to the contributor list
> https://git.sr.ht/~bzg/worg/commit/c5020487
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>
[-- Attachment #2: Type: text/html, Size: 1566 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-10-18 20:18 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-15 17:43 ob-clojure breaks tangling of comments using org-babel-tangle for clojure source code blocks Anoop GR
2024-10-15 17:51 ` Anoop GR
2024-10-15 17:52 ` Anoop GR
2024-10-15 17:53 ` Anoop GR
2024-10-16 19:49 ` Ihor Radchenko
2024-10-17 13:42 ` Anoop GR
2024-10-17 17:59 ` Ihor Radchenko
2024-10-18 10:18 ` Anoop GR
2024-10-18 17:23 ` Ihor Radchenko
2024-10-18 20:16 ` Anoop GR
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).