From: Daniel Kraus <daniel@kraus.my> To: emacs-orgmode@gnu.org Subject: Re: [PATCH] ob-clojure.el: Add support for babashka and nbb backend Date: Mon, 15 Nov 2021 17:05:43 +0100 [thread overview] Message-ID: <87o86lo0wv.fsf@kraus.my> (raw) In-Reply-To: <smtr3v$chu$1@ciao.gmane.io> [-- Attachment #1: Type: text/plain, Size: 473 bytes --] Max Nikulin <manikulin@gmail.com> writes: > The following source block must not execute echo and touch > > #+begin_src clojure > (str "`echo $HOME`" "`touch /tmp/pwned`") > #+end_src Thanks, now I got it :) Attached is the patch changed the logic to use a temp file with org-babel-eval. Somehow it doesn't feel too great to create unnecessary temp files but I looked how other babel backends do it and e.g. ob-js and ob-haskell use the same logic. Thanks, Daniel [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-clojure.el-Add-support-for-babashka-and-nbb-backe.patch --] [-- Type: text/x-patch, Size: 2903 bytes --] From cc9a24fcc42756cc76d59697bddc94a4ee2c475d Mon Sep 17 00:00:00 2001 From: Daniel Kraus <daniel@kraus.my> Date: Sat, 13 Nov 2021 22:51:56 +0100 Subject: [PATCH] ob-clojure.el: Add support for babashka and nbb backend * lisp/ob-clojure.el: Add support for babashka and nbb backend. --- lisp/ob-clojure.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el index 3b995d94c..8548dc86d 100644 --- a/lisp/ob-clojure.el +++ b/lisp/ob-clojure.el @@ -36,6 +36,8 @@ ;; For clojure-mode, see https://github.com/clojure-emacs/clojure-mode ;; For cider, see https://github.com/clojure-emacs/cider ;; For inf-clojure, see https://github.com/clojure-emacs/cider +;; For babashka, see https://github.com/babashka/babashka +;; For nbb, see https://github.com/babashka/nbb ;; For SLIME, the best way to install these components is by following ;; the directions as set out by Phil Hagelberg (Technomancy) on the @@ -73,6 +75,8 @@ (const :tag "inf-clojure" inf-clojure) (const :tag "cider" cider) (const :tag "slime" slime) + (const :tag "babashka" babashka) + (const :tag "nbb" nbb) (const :tag "Not configured yet" nil))) (defcustom org-babel-clojure-default-ns "user" @@ -80,6 +84,16 @@ :type 'string :group 'org-babel) +(defcustom ob-clojure-babashka-command (executable-find "bb") + "Path to the babashka executable." + :type 'file + :group 'org-babel) + +(defcustom ob-clojure-nbb-command (executable-find "nbb") + "Path to the nbb executable." + :type 'file + :group 'org-babel) + (defun org-babel-expand-body:clojure (body params) "Expand BODY according to PARAMS, return the expanded body." (let* ((vars (org-babel--get-vars params)) @@ -225,6 +239,15 @@ ,(buffer-substring-no-properties (point-min) (point-max))) (cdr (assq :package params))))) +(defun ob-clojure-eval-with-babashka (bb expanded) + "Evaluate EXPANDED code block using BB (babashka or nbb)." + (let ((script-file (org-babel-temp-file "clojure-bb-script-" ".clj"))) + (with-temp-file script-file + (insert expanded)) + (org-babel-eval + (format "%s %s" bb (org-babel-process-file-name script-file)) + ""))) + (defun org-babel-execute:clojure (body params) "Execute a block of Clojure code with Babel." (unless org-babel-clojure-backend @@ -236,6 +259,10 @@ (cond ((eq org-babel-clojure-backend 'inf-clojure) (ob-clojure-eval-with-inf-clojure expanded params)) + ((eq org-babel-clojure-backend 'babashka) + (ob-clojure-eval-with-babashka ob-clojure-babashka-command expanded)) + ((eq org-babel-clojure-backend 'nbb) + (ob-clojure-eval-with-babashka ob-clojure-nbb-command expanded)) ((eq org-babel-clojure-backend 'cider) (ob-clojure-eval-with-cider expanded params)) ((eq org-babel-clojure-backend 'slime) -- 2.33.1
next prev parent reply other threads:[~2021-11-15 16:11 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-14 15:28 Daniel Kraus 2021-11-14 16:25 ` Max Nikulin 2021-11-14 16:30 ` Daniel Kraus 2021-11-15 14:33 ` Max Nikulin 2021-11-15 16:05 ` Daniel Kraus [this message] 2021-11-17 16:12 ` Max Nikulin 2021-11-20 10:18 ` Daniel Kraus 2021-12-22 22:34 ` Daniel Kraus 2022-01-31 7:58 ` Daniel Kraus 2022-02-02 15:58 ` Max Nikulin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=87o86lo0wv.fsf@kraus.my \ --to=daniel@kraus.my \ --cc=emacs-orgmode@gnu.org \ --subject='Re: [PATCH] ob-clojure.el: Add support for babashka and nbb backend' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this 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).