unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / Atom feed
* patch: ob-clojure improvements
@ 2020-06-20  6:55 Ag Ibragimov
  2020-06-20  8:23 ` stardiviner
  2020-10-09 21:17 ` joseph.corneli.orgmode--- via General discussions about Org-mode.
  0 siblings, 2 replies; 7+ messages in thread
From: Ag Ibragimov @ 2020-06-20  6:55 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi everyone, here's my attempt to add clojure CLI and babashka support for ob-clojure.el

- Adds a header parameter to override org-babel-clojure-backend
- Adds :args param (right now only used for clojure-cli)

I have tested it with these minimal cases:

#+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections {:mvn/version \"0.13.2\"}}}'"
  (use 'inflections.core)
  (plural "word")
#+end_src

#+begin_src clojure :backend babashka :results output
  (range 10)
#+end_src

Please let me know what you think. Any advice is appreciated, since I have never contributed before. Thank you.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-clojure-improvements.patch --]
[-- Type: text/x-patch, Size: 3538 bytes --]

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 299a326e4..4e79a2c24 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -61,7 +61,13 @@ (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
 (add-to-list 'org-babel-tangle-lang-exts '("clojurescript" . "cljs"))
 
 (defvar org-babel-default-header-args:clojure '())
-(defvar org-babel-header-args:clojure '((ns . :any) (package . :any)))
+
+(defvar org-babel-header-args:clojure
+  '((ns . :any)
+    (package . :any)
+    (backend . ((inf-clojure cider slime clj-cli babashka)))
+    (args . :any)))
+
 (defvar org-babel-default-header-args:clojurescript '())
 (defvar org-babel-header-args:clojurescript '((package . :any)))
 
@@ -224,25 +230,47 @@ (defun ob-clojure-eval-with-slime (expanded params)
        ,(buffer-substring-no-properties (point-min) (point-max)))
      (cdr (assq :package params)))))
 
+(defun ob-clojure-eval-with-babashka (expanded params)
+  "Evaluate EXPANDED code block with PARAMS using babashka."
+  (let ((exe (executable-find "bb")))
+    (unless exe (user-error "babashka CLI (bb) not found."))
+    (org-babel-execute:shell
+     (format "%s -e %S" exe expanded) params)))
+
+(defun ob-clojure-eval-with-clj-cli (expanded params)
+  "Evaluate EXPANDED code block with PARAMS using clojure-cli."
+  (let* ((args (cdr (assq :args params)))
+	 (exe (executable-find "clj")))
+    (unless exe (user-error "clj CLI tool not found."))
+    (org-babel-execute:shell
+     (format "%s %s -e %S" exe args expanded) params)))
+
 (defun org-babel-execute:clojure (body params)
   "Execute a block of Clojure code with Babel."
-  (unless org-babel-clojure-backend
-    (user-error "You need to customize org-babel-clojure-backend"))
-  (let* ((expanded (org-babel-expand-body:clojure body params))
-	 (result-params (cdr (assq :result-params params)))
-	 result)
-    (setq result
-	  (cond
-	   ((eq org-babel-clojure-backend 'inf-clojure)
-	    (ob-clojure-eval-with-inf-clojure expanded params))
-	   ((eq org-babel-clojure-backend 'cider)
-	    (ob-clojure-eval-with-cider expanded params))
-	   ((eq org-babel-clojure-backend 'slime)
-	    (ob-clojure-eval-with-slime expanded params))))
-    (org-babel-result-cond result-params
-      result
-      (condition-case nil (org-babel-script-escape result)
-	(error result)))))
+  (let* ((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")))))
+    (let* ((expanded (org-babel-expand-body:clojure body params))
+	   (result-params (cdr (assq :result-params params)))
+	   result)
+      (setq result
+	    (cond
+	     ((eq org-babel-clojure-backend 'inf-clojure)
+	      (ob-clojure-eval-with-inf-clojure expanded params))
+	     ((eq org-babel-clojure-backend 'cider)
+	      (ob-clojure-eval-with-cider expanded params))
+	     ((eq org-babel-clojure-backend 'slime)
+	      (ob-clojure-eval-with-slime expanded params))
+	     ((eq org-babel-clojure-backend 'babashka)
+	      (ob-clojure-eval-with-babashka expanded params))
+	     ((eq org-babel-clojure-backend 'clj-cli)
+	      (ob-clojure-eval-with-clj-cli expanded params))))
+      (org-babel-result-cond result-params
+	result
+	(condition-case nil (org-babel-script-escape result)
+	  (error result))))))
 
 (defun org-babel-execute:clojurescript (body params)
   "Evaluate BODY with PARAMS as ClojureScript code."

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

* Re: patch: ob-clojure improvements
  2020-06-20  6:55 patch: ob-clojure improvements Ag Ibragimov
@ 2020-06-20  8:23 ` stardiviner
  2020-07-02 22:43   ` agzam.ibragimov
  2020-10-09 21:17 ` joseph.corneli.orgmode--- via General discussions about Org-mode.
  1 sibling, 1 reply; 7+ messages in thread
From: stardiviner @ 2020-06-20  8:23 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-orgmode


Glad to see your patch, really useful in some cases. Thanks.

Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> Hi everyone, here's my attempt to add clojure CLI and babashka support for ob-clojure.el
>
> - Adds a header parameter to override org-babel-clojure-backend
> - Adds :args param (right now only used for clojure-cli)
>
> I have tested it with these minimal cases:
>
> #+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections {:mvn/version \"0.13.2\"}}}'"
>   (use 'inflections.core)
>   (plural "word")
> #+end_src
>
> #+begin_src clojure :backend babashka :results output
>   (range 10)
> #+end_src
>
> Please let me know what you think. Any advice is appreciated, since I have never contributed before. Thank you.


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

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


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

* Re: patch: ob-clojure improvements
  2020-06-20  8:23 ` stardiviner
@ 2020-07-02 22:43   ` agzam.ibragimov
  2020-07-03  3:10     ` stardiviner
  2020-09-04 15:24     ` Bastien
  0 siblings, 2 replies; 7+ messages in thread
From: agzam.ibragimov @ 2020-07-02 22:43 UTC (permalink / raw)
  To: numbchild; +Cc: org-mode-email

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

There seems to be a bit of lack of interest for these things. But I'm sure
some people (myself included) would love to see these kinds of
improvements. As I said before, I have never participated in contributing
to Org source, some guidance would be appreciated. Should I keep building
it and posting patches? Should I try to go incrementally, one small change
at a time, or should I just get everything working first? If it turns out
to be a bigger work, should I ask for permission to work in a branch and
get access to pushing things to it?
Maybe things just move slowly, because obviously you can't force
maintainers to drop everything and concentrate effort to get your things
in. Maybe I just have to be a little bit more patient?

On Sat, Jun 20, 2020 at 1:23 AM stardiviner <numbchild@gmail.com> wrote:

>
> Glad to see your patch, really useful in some cases. Thanks.
>
> Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
>
> > Hi everyone, here's my attempt to add clojure CLI and babashka support
> for ob-clojure.el
> >
> > - Adds a header parameter to override org-babel-clojure-backend
> > - Adds :args param (right now only used for clojure-cli)
> >
> > I have tested it with these minimal cases:
> >
> > #+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections
> {:mvn/version \"0.13.2\"}}}'"
> >   (use 'inflections.core)
> >   (plural "word")
> > #+end_src
> >
> > #+begin_src clojure :backend babashka :results output
> >   (range 10)
> > #+end_src
> >
> > Please let me know what you think. Any advice is appreciated, since I
> have never contributed before. Thank you.
>
>
> --
> [ stardiviner ]
>        I try to make every word tell the meaning that I want to express.
>
>        Blog: https://stardiviner.github.io/
>        IRC(freenode): stardiviner, Matrix: stardiviner
>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>


-- 
Regards,
Ag.

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

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

* Re: patch: ob-clojure improvements
  2020-07-02 22:43   ` agzam.ibragimov
@ 2020-07-03  3:10     ` stardiviner
  2020-07-03  3:53       ` Tim Cross
  2020-09-04 15:24     ` Bastien
  1 sibling, 1 reply; 7+ messages in thread
From: stardiviner @ 2020-07-03  3:10 UTC (permalink / raw)
  To: agzam.ibragimov; +Cc: Bastien Guerry, org-mode-email


agzam.ibragimov@gmail.com writes:

> There seems to be a bit of lack of interest for these things. But I'm sure
> some people (myself included) would love to see these kinds of
> improvements.

Yes, I rarely saw Clojurians in this mailing list.

> As I said before, I have never participated in contributing
> to Org source, some guidance would be appreciated.

Org Mode has contribution guide here http://orgmode.org/worg/org-contribute.html#patches

> Should I keep building it and posting patches? Should I try to go
> incrementally, one small change at a time, or should I just get everything
> working first? If it turns out to be a bigger work, should I ask for
> permission to work in a branch and get access to pushing things to it? Maybe
> things just move slowly, because obviously you can't force maintainers to drop
> everything and concentrate effort to get your things in. Maybe I just have to
> be a little bit more patient?

I think a complete work contains many patches should be better, Also write testing if necessary.

I remember ob-clojure.el code are mostly reviewed by Bastien Guerry. I included him in Cc: in this email.

> On Sat, Jun 20, 2020 at 1:23 AM stardiviner <numbchild@gmail.com> wrote:
>
>>
>> Glad to see your patch, really useful in some cases. Thanks.
>>
>> Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
>>
>> > Hi everyone, here's my attempt to add clojure CLI and babashka support
>> for ob-clojure.el
>> >
>> > - Adds a header parameter to override org-babel-clojure-backend
>> > - Adds :args param (right now only used for clojure-cli)
>> >
>> > I have tested it with these minimal cases:
>> >
>> > #+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections
>> {:mvn/version \"0.13.2\"}}}'"
>> >   (use 'inflections.core)
>> >   (plural "word")
>> > #+end_src
>> >
>> > #+begin_src clojure :backend babashka :results output
>> >   (range 10)
>> > #+end_src
>> >
>> > Please let me know what you think. Any advice is appreciated, since I
>> have never contributed before. Thank you.
>>
>>
>> --
>> [ stardiviner ]
>>        I try to make every word tell the meaning that I want to express.
>>
>>        Blog: https://stardiviner.github.io/
>>        IRC(freenode): stardiviner, Matrix: stardiviner
>>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>>


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

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


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

* Re: patch: ob-clojure improvements
  2020-07-03  3:10     ` stardiviner
@ 2020-07-03  3:53       ` Tim Cross
  0 siblings, 0 replies; 7+ messages in thread
From: Tim Cross @ 2020-07-03  3:53 UTC (permalink / raw)
  To: emacs-orgmode


I am also interested in ob-clojure and ob-clojurescript improvements.
However, right now, I'm a tad busy and haven't had time to review what
has been done. Hopefully, can make some time in the next month or so.

Tim

stardiviner <numbchild@gmail.com> writes:

> agzam.ibragimov@gmail.com writes:
>
>> There seems to be a bit of lack of interest for these things. But I'm sure
>> some people (myself included) would love to see these kinds of
>> improvements.
>
> Yes, I rarely saw Clojurians in this mailing list.
>
>> As I said before, I have never participated in contributing
>> to Org source, some guidance would be appreciated.
>
> Org Mode has contribution guide here http://orgmode.org/worg/org-contribute.html#patches
>
>> Should I keep building it and posting patches? Should I try to go
>> incrementally, one small change at a time, or should I just get everything
>> working first? If it turns out to be a bigger work, should I ask for
>> permission to work in a branch and get access to pushing things to it? Maybe
>> things just move slowly, because obviously you can't force maintainers to drop
>> everything and concentrate effort to get your things in. Maybe I just have to
>> be a little bit more patient?
>
> I think a complete work contains many patches should be better, Also write testing if necessary.
>
> I remember ob-clojure.el code are mostly reviewed by Bastien Guerry. I included him in Cc: in this email.
>
>> On Sat, Jun 20, 2020 at 1:23 AM stardiviner <numbchild@gmail.com> wrote:
>>
>>>
>>> Glad to see your patch, really useful in some cases. Thanks.
>>>
>>> Ag Ibragimov <agzam.ibragimov@gmail.com> writes:
>>>
>>> > Hi everyone, here's my attempt to add clojure CLI and babashka support
>>> for ob-clojure.el
>>> >
>>> > - Adds a header parameter to override org-babel-clojure-backend
>>> > - Adds :args param (right now only used for clojure-cli)
>>> >
>>> > I have tested it with these minimal cases:
>>> >
>>> > #+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections
>>> {:mvn/version \"0.13.2\"}}}'"
>>> >   (use 'inflections.core)
>>> >   (plural "word")
>>> > #+end_src
>>> >
>>> > #+begin_src clojure :backend babashka :results output
>>> >   (range 10)
>>> > #+end_src
>>> >
>>> > Please let me know what you think. Any advice is appreciated, since I
>>> have never contributed before. Thank you.
>>>
>>>
>>> --
>>> [ stardiviner ]
>>>        I try to make every word tell the meaning that I want to express.
>>>
>>>        Blog: https://stardiviner.github.io/
>>>        IRC(freenode): stardiviner, Matrix: stardiviner
>>>        GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>>>


-- 
Tim Cross


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

* Re: patch: ob-clojure improvements
  2020-07-02 22:43   ` agzam.ibragimov
  2020-07-03  3:10     ` stardiviner
@ 2020-09-04 15:24     ` Bastien
  1 sibling, 0 replies; 7+ messages in thread
From: Bastien @ 2020-09-04 15:24 UTC (permalink / raw)
  To: agzam.ibragimov; +Cc: org-mode-email

Hi Agzam,

agzam.ibragimov@gmail.com writes:

> There seems to be a bit of lack of interest for these things. But I'm
> sure some people (myself included) would love to see these kinds of
> improvements. 

I'm very interested in improvements to ob-clojure*.el, thanks for the
work you did on it and sorry for the delay in replying.

I will have a look after 9.4 is released.

Best,

-- 
 Bastien


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

* Re: patch: ob-clojure improvements
  2020-06-20  6:55 patch: ob-clojure improvements Ag Ibragimov
  2020-06-20  8:23 ` stardiviner
@ 2020-10-09 21:17 ` joseph.corneli.orgmode--- via General discussions about Org-mode.
  1 sibling, 0 replies; 7+ messages in thread
From: joseph.corneli.orgmode--- via General discussions about Org-mode. @ 2020-10-09 21:17 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-orgmode

Nice work, I did some testing here...

* Comment: Should babashka be added as an option for custom?

(defcustom org-babel-clojure-backend nil
   "Backend used to evaluate Clojure code blocks."
   :group 'org-babel
   :type '(choice
	  (const :tag "inf-clojure" inf-clojure)
	  (const :tag "cider" cider)
	  (const :tag "slime" slime)
	  (const :tag "Not configured yet" nil)))

* I wonder if there’s something wrong here?

... Inside ‘ob-clojure-eval-with-cider’

(push (or (nrepl-dict-get response "root-ex")
		    (nrepl-dict-get response "ex")
		    (nrepl-dict-get
		     response (if (or (member "output" result-params)
				      (member "pp" result-params))
				  "out"
				"value")))
		result0)

That didn’t work for me, using an instance of Cider *connected to
babashka*.  But it did work when I swapped "value" and "out"!

- Testing code and inspecting with edebug:

#+begin_src clojure :backend cider :results output
   (range 10)
#+end_src

* Lastly, the documentation and implementation have drifted apart...?

https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html

Ag Ibragimov writes:

> Hi everyone, here's my attempt to add clojure CLI and babashka support 
> for ob-clojure.el
> 
> - Adds a header parameter to override org-babel-clojure-backend
> - Adds :args param (right now only used for clojure-cli)
> 
> I have tested it with these minimal cases:
> 
> #+begin_src clojure :backend clj-cli :args "-Sdeps '{:deps {inflections 
> {:mvn/version \"0.13.2\"}}}'"
>   (use 'inflections.core)
>   (plural "word")
> #+end_src
> 
> #+begin_src clojure :backend babashka :results output
>   (range 10)
> #+end_src
> 
> Please let me know what you think. Any advice is appreciated, since I 
> have never contributed before. Thank you.


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

end of thread, other threads:[~2020-10-09 21:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20  6:55 patch: ob-clojure improvements Ag Ibragimov
2020-06-20  8:23 ` stardiviner
2020-07-02 22:43   ` agzam.ibragimov
2020-07-03  3:10     ` stardiviner
2020-07-03  3:53       ` Tim Cross
2020-09-04 15:24     ` Bastien
2020-10-09 21:17 ` joseph.corneli.orgmode--- via General discussions about Org-mode.

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git