From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id aIEIMRaz7V6vMgAA0tVLHw (envelope-from ) for ; Sat, 20 Jun 2020 06:56:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 4L3pLBaz7V4KTgAAB5/wlQ (envelope-from ) for ; Sat, 20 Jun 2020 06:56:22 +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 1BBEF94051C for ; Sat, 20 Jun 2020 06:56:21 +0000 (UTC) Received: from localhost ([::1]:56344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmXQJ-00026e-AA for larch@yhetil.org; Sat, 20 Jun 2020 02:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmXPu-00026W-4U for emacs-orgmode@gnu.org; Sat, 20 Jun 2020 02:55:54 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:36988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmXPs-00020P-Dt for emacs-orgmode@gnu.org; Sat, 20 Jun 2020 02:55:53 -0400 Received: by mail-pl1-x631.google.com with SMTP id y18so4968509plr.4 for ; Fri, 19 Jun 2020 23:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:user-agent:from:to:subject:message-id:date:mime-version; bh=ulcfzkbFxBbOZK+NQjFUHJyhx+RUyeUiSowlHuQmPpA=; b=KLzwesjsscHRiNwfHU4qOSlKGVnD2vr+vFNsdPuqLV9zgJZ1xYdFZm78cPvAUJcfLB snx0v0HrNip3KCiO7ECtxOcYbv1BcNtjWJOT0zLGLXpGHz2kG8/l0t1W8fBYh6XwWl8T VsO/TGmXImjZRMg1eWlmbxMmp8Wm4R5Ezly4JHBg+02sYzXtq5JNoxfxMtoy+QBALuS4 Ypzl9XxJ2xQl/JyjVLgDgWJ13QjKX8I+uH6D5vqM/bTfzJ1ghi+VmZH4NeNKUyqqOKK9 Hos9D60SLw0iuAWpXbEDL0LeJ3DYSybfgnD1WZviXKX/1lk7pWXS4qmWtM30ZgazUD2B YzEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:user-agent:from:to:subject:message-id :date:mime-version; bh=ulcfzkbFxBbOZK+NQjFUHJyhx+RUyeUiSowlHuQmPpA=; b=J6gTCnS0jTgHh5YQqQG3w0KhGw28jxsTX1f1R1YnfmipjYoYpN8SfNQefU1c6EaGEE p7xR+UAxde41lIjXRHzrr5g+j6BKlpYzkh67sOKcganH2XIg/iDA9ZoS6tmGz+uGhPDx avOkuVuuYs50is25A4YM5ADYNsbseuXX/nu8Ou1D+55j97Mc/9/thBy4mtjQTO1OQ1h9 XLKej4hGZveqSAb59l1khl41o0NieIsOu5p53Q6thnqAqgaed3XoDLR+jewxzm1LH8lL Xyt6YUPcbDj/1ITfuW5+Q8Om0QhlnTMuf0uz0yUjPfQV5XSYJJW53WEqVnsWrUSqqCaR +UOg== X-Gm-Message-State: AOAM533xSa/nQjJClo8PHT1Dhzb9Hm/Lwly1TQIO7d7C8frvpfEXYjyz 9QbhlRiN9vH0hpIz29zDNHyPtWs09oc= X-Google-Smtp-Source: ABdhPJxMW4uVFGFrlmt4e8E/FzvLD/b0+2R5/wP5iNLPsvVt8pV/d6/rFubDGt/MkQAYJoyJqFFvlg== X-Received: by 2002:a17:902:8c84:: with SMTP id t4mr10992190plo.315.1592636150274; Fri, 19 Jun 2020 23:55:50 -0700 (PDT) Received: from AIBRAGIM-M-J8Z8 ([2001:420:c0c8:1003::7d6]) by smtp.gmail.com with ESMTPSA id 200sm7941386pfb.15.2020.06.19.23.55.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jun 2020 23:55:49 -0700 (PDT) User-agent: mu4e 1.4.10; emacs 28.0.50 From: Ag Ibragimov To: emacs-orgmode Subject: patch: ob-clojure improvements Message-ID: Date: Fri, 19 Jun 2020 23:55:48 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=agzam.ibragimov@gmail.com; helo=mail-pl1-x631.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=KLzwesjs; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: qW87wYwgU4AJ --=-=-= Content-Type: text/plain; format=flowed 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ob-clojure-improvements.patch 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." --=-=-=--