From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id CKjdOuMrkWHpoQAAgWs5BA (envelope-from ) for ; Sun, 14 Nov 2021 16:31:47 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id mACQNuMrkWFvdQAA1q6Kng (envelope-from ) for ; Sun, 14 Nov 2021 15:31:47 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6A4173E09D for ; Sun, 14 Nov 2021 16:31:47 +0100 (CET) Received: from localhost ([::1]:42776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmHTu-0004CK-H6 for larch@yhetil.org; Sun, 14 Nov 2021 10:31:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmHRx-0004AU-4G for emacs-orgmode@gnu.org; Sun, 14 Nov 2021 10:29:45 -0500 Received: from mout-p-201.mailbox.org ([80.241.56.171]:57838) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1mmHRu-0003yA-3X for emacs-orgmode@gnu.org; Sun, 14 Nov 2021 10:29:44 -0500 Received: from smtp102.mailbox.org (smtp102.mailbox.org [80.241.60.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Hsbpg2qR5zQjgG for ; Sun, 14 Nov 2021 16:29:31 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kraus.my; s=MBO0001; t=1636903769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=oLtRr3s9mv+IzLrtr2my0XY9VNwRaotKu7l1MNsMyl4=; b=LV4cswjrIKbGlnU28NS2Wf8rkEc4Cq7l3GSuSGZUUfQ+nJjptzaGBWYcSGvr9LXlol+pyf X/w3bPRlD2UvSue3Km4qm1B/q+r7CXaaFLwYni8FqsWzOjsI/B05BnJR+YCyxYLHET9ZE/ UwsP7n3HbQrHPY2vBmbTt5Oslmjh1N1O8zJpITRKZrX/VhoC8ltKmhw7BXyxsTk4wGaiIY lyRiBxFcSk0V4pd9SRifS9XYmbjy79Y6legZ66irLvNVTvnvJkVYYD0nMLvip//FXxW7zf M9iFWa2DoN7q9qqBaKi4BqlBT3mWJwLF3B5JmFwr6OLe0fkCPqZl0wZNNu+uyg== From: Daniel Kraus To: emacs-orgmode@gnu.org Subject: [PATCH] ob-clojure.el: Add support for babashka and nbb backend Date: Sun, 14 Nov 2021 16:28:01 +0100 Message-ID: <87bl2mycxq.fsf@kraus.my> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: none client-ip=80.241.56.171; envelope-from=daniel@kraus.my; helo=mout-p-201.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636903907; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=oLtRr3s9mv+IzLrtr2my0XY9VNwRaotKu7l1MNsMyl4=; b=I1ihaopkwdV72qqm5dzMt2snfcwzIHQoGq+BzYcqdM7LP1RMEUHDB7ro403OUjZ87lxZA0 OvPx6q5r3+rRUVMsPMqheu1xCRXsiAUr29uHilJbGPtuYoQdo+BqPMN+Or8p2tufZoKvhC 8mx6HHDd5HDtvTtX0mfdTK19qeLQ6JQi3xPBWh+ymxhFY6sRfvFuq0qChWfttVrFlQY3wY 9lSXn+jTHpUrYit8/V/iWd1iqgZmHMS24F/o9jPDZ4YqtlyQqtsE0q/rnQIv/MP1T/vbA4 kxpFjxiYJuEw+Ju5DqSTiVJ8Joni/D3qDJUtI1MlNI+kfhwdSZerUiG8aoB0rw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636903907; a=rsa-sha256; cv=none; b=acBrQqgvxhY0gi0d2/nVv4OAuCB4BTiwjWKWICsUF9fSgr/R9cBck/9zfwGX4qYQSta/gP +64vk7o7YU4IZR5PLKTSPcnxi8Y4I+tnCzVH1tC26JaLYvyRyi733sqU+WfCZRDzvd8MoA l/tJw7ZJXRdkRWcXO4l3vY06nz1wVta4lL3PvBJ9PORC/LdTsSBny/rpDR/10yUbWvtCsn 2Ewha6cexYVZcU6ow+tX5CxlfTzbrILPD/H+YLCbjNY59XcB9/kJ5ygQsdq2I4duVl9TO2 gxO0cL6+jran5tMPKgfMOd+SoID0Y5meQshoEwRVhkzv44OODivW6oA4XNb9AQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=kraus.my header.s=MBO0001 header.b=LV4cswjr; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.64 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=kraus.my header.s=MBO0001 header.b=LV4cswjr; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 6A4173E09D X-Spam-Score: -3.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: lEX81ELQ/zxV * lisp/ob-clojure.el: Add support for babashka and nbb backend. --- This adds support to ob-clojure for babashka (https://github.com/babashka/babashka) and nbb (node version of babashka). It doesn't use `params` as I'm not really sure what they're used for and if they're important for evaluation. I'm also new to org development and the git email workflow so any feedback to the code or the email patch etc is appreciated. lisp/ob-clojure.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el index 3b995d94c..dc42daa5c 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,16 @@ ,(buffer-substring-no-properties (point-min) (point-max))) (cdr (assq :package params))))) +(defun ob-clojure-escape-quotes (str-val) + "Escape quotes for STR-VAL." + (replace-regexp-in-string "\"" "\\\"" str-val 'FIXEDCASE 'LITERAL)) + +(defun ob-clojure-eval-with-babashka (bb expanded) + "Evaluate EXPANDED code block using BB (babashka or nbb)." + (let ((escaped (ob-clojure-escape-quotes expanded))) + (shell-command-to-string + (concat bb " -e \"" escaped "\"")))) + (defun org-babel-execute:clojure (body params) "Execute a block of Clojure code with Babel." (unless org-babel-clojure-backend @@ -236,6 +260,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