2015-10-26 00:56:00 +00:00
|
|
|
;;; ob-clojure.el --- Babel Functions for Clojure -*- lexical-binding: t; -*-
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2016-11-18 17:01:02 +00:00
|
|
|
;; Author: Joel Boehland, Eric Schulte, Oleh Krehel, Frederick Giasson
|
2022-09-27 19:36:33 +00:00
|
|
|
;; Maintainer: Daniel Kraus <daniel@kraus.my>
|
2013-10-03 16:23:16 +00:00
|
|
|
;;
|
2009-11-09 21:17:34 +00:00
|
|
|
;; Keywords: literate programming, reproducible research
|
2021-09-26 07:44:29 +00:00
|
|
|
;; URL: https://orgmode.org
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2010-06-25 16:32:35 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2010-06-25 16:32:35 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2009-11-09 21:17:34 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2010-06-25 16:32:35 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2009-11-09 21:17:34 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2010-06-25 16:32:35 +00:00
|
|
|
|
2009-11-09 21:17:34 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-11-09 21:17:34 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2023-03-09 15:11:27 +00:00
|
|
|
;; Support for evaluating Clojure / ClojureScript code.
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2013-11-04 10:30:34 +00:00
|
|
|
;; Requirements:
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2022-10-28 08:48:16 +00:00
|
|
|
;; - Clojure (at least 1.2.0)
|
2013-11-04 10:30:34 +00:00
|
|
|
;; - clojure-mode
|
2023-03-09 15:11:27 +00:00
|
|
|
;; - babashka, nbb, Clojure CLI tools, Cider, inf-clojure or SLIME
|
2009-11-09 21:17:34 +00:00
|
|
|
|
2020-02-16 10:16:00 +00:00
|
|
|
;; For clojure-mode, see https://github.com/clojure-emacs/clojure-mode
|
2021-11-13 21:51:56 +00:00
|
|
|
;; For babashka, see https://github.com/babashka/babashka
|
|
|
|
;; For nbb, see https://github.com/babashka/nbb
|
2023-03-09 15:11:27 +00:00
|
|
|
;; For Clojure CLI tools, see https://clojure.org/guides/deps_and_cli
|
|
|
|
;; For Cider, see https://github.com/clojure-emacs/cider
|
|
|
|
;; For inf-clojure, see https://github.com/clojure-emacs/inf-clojure
|
|
|
|
;; For SLIME, see https://slime.common-lisp.dev
|
2013-10-03 16:23:16 +00:00
|
|
|
|
2022-10-28 08:48:16 +00:00
|
|
|
;; For SLIME, the best way to install its components is by following
|
2013-11-04 10:30:34 +00:00
|
|
|
;; the directions as set out by Phil Hagelberg (Technomancy) on the
|
2021-03-21 18:55:14 +00:00
|
|
|
;; web page: https://technomancy.us/126
|
2013-11-04 10:30:34 +00:00
|
|
|
|
2009-11-09 21:17:34 +00:00
|
|
|
;;; Code:
|
2022-08-04 13:53:05 +00:00
|
|
|
|
|
|
|
(require 'org-macs)
|
|
|
|
(org-assert-version)
|
|
|
|
|
2010-06-11 23:02:42 +00:00
|
|
|
(require 'ob)
|
2010-07-03 02:21:31 +00:00
|
|
|
|
2015-10-11 21:56:35 +00:00
|
|
|
(declare-function cider-current-connection "ext:cider-client" (&optional type))
|
2017-03-07 08:00:27 +00:00
|
|
|
(declare-function cider-current-ns "ext:cider-client" ())
|
2020-02-16 22:43:56 +00:00
|
|
|
(declare-function inf-clojure "ext:inf-clojure" (cmd))
|
|
|
|
(declare-function inf-clojure-cmd "ext:inf-clojure" (project-type))
|
|
|
|
(declare-function inf-clojure-eval-string "ext:inf-clojure" (code))
|
|
|
|
(declare-function inf-clojure-project-type "ext:inf-clojure" ())
|
2014-10-13 20:05:12 +00:00
|
|
|
(declare-function nrepl-dict-get "ext:nrepl-client" (dict key))
|
2018-03-26 03:35:21 +00:00
|
|
|
(declare-function nrepl-sync-request:eval "ext:nrepl-client" (input connection &optional ns tooling))
|
2020-02-16 22:43:56 +00:00
|
|
|
(declare-function sesman-start-session "ext:sesman" (system))
|
2013-11-04 10:30:34 +00:00
|
|
|
(declare-function slime-eval "ext:slime" (sexp &optional package))
|
|
|
|
|
2018-03-26 03:35:21 +00:00
|
|
|
(defvar cider-buffer-ns)
|
2016-11-18 17:01:02 +00:00
|
|
|
|
2011-06-21 22:34:41 +00:00
|
|
|
(defvar org-babel-tangle-lang-exts)
|
2010-06-17 17:21:14 +00:00
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
|
2020-02-13 15:23:03 +00:00
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("clojurescript" . "cljs"))
|
2010-06-17 17:21:14 +00:00
|
|
|
|
2010-06-25 17:12:54 +00:00
|
|
|
(defvar org-babel-default-header-args:clojure '())
|
2022-10-08 09:41:20 +00:00
|
|
|
(defvar org-babel-header-args:clojure
|
|
|
|
'((ns . :any)
|
|
|
|
(package . :any)
|
|
|
|
(backend . ((inf-clojure cider slime babashka nbb)))))
|
2020-02-13 15:23:03 +00:00
|
|
|
(defvar org-babel-default-header-args:clojurescript '())
|
|
|
|
(defvar org-babel-header-args:clojurescript '((package . :any)))
|
|
|
|
|
2022-10-29 21:20:06 +00:00
|
|
|
(defcustom org-babel-clojure-backend (cond
|
|
|
|
((executable-find "bb") 'babashka)
|
2023-03-09 15:11:27 +00:00
|
|
|
((executable-find "clojure") 'clojure-cli)
|
2022-10-29 21:20:06 +00:00
|
|
|
((featurep 'cider) 'cider)
|
|
|
|
((featurep 'inf-clojure) 'inf-clojure)
|
|
|
|
((featurep 'slime) 'slime)
|
|
|
|
(t nil))
|
2020-02-16 10:16:00 +00:00
|
|
|
"Backend used to evaluate Clojure code blocks."
|
|
|
|
:group 'org-babel
|
2023-03-09 15:11:27 +00:00
|
|
|
:package-version '(Org . "9.7")
|
2020-02-16 10:16:00 +00:00
|
|
|
:type '(choice
|
2023-03-09 15:11:27 +00:00
|
|
|
(const :tag "babashka" babashka)
|
|
|
|
(const :tag "clojure-cli" clojure-cli)
|
2020-02-16 10:16:00 +00:00
|
|
|
(const :tag "cider" cider)
|
2023-03-09 15:11:27 +00:00
|
|
|
(const :tag "inf-clojure" inf-clojure)
|
2020-02-16 10:16:00 +00:00
|
|
|
(const :tag "slime" slime)
|
2023-03-09 15:11:27 +00:00
|
|
|
(const :tag "Not configured yet" nil)))
|
|
|
|
|
|
|
|
(defcustom org-babel-clojurescript-backend
|
|
|
|
(cond
|
|
|
|
((or (executable-find "nbb") (executable-find "npx")) 'nbb)
|
|
|
|
((featurep 'cider) 'cider)
|
|
|
|
(t nil))
|
|
|
|
"Backend used to evaluate ClojureScript code blocks."
|
|
|
|
:group 'org-babel
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type '(choice
|
2021-11-13 21:51:56 +00:00
|
|
|
(const :tag "nbb" nbb)
|
2023-03-09 15:11:27 +00:00
|
|
|
(const :tag "cider" cider)
|
2020-02-16 10:16:00 +00:00
|
|
|
(const :tag "Not configured yet" nil)))
|
|
|
|
|
2018-03-26 03:35:21 +00:00
|
|
|
(defcustom org-babel-clojure-default-ns "user"
|
2018-09-20 09:23:49 +00:00
|
|
|
"Default Clojure namespace for source block when finding ns failed."
|
2018-03-26 03:35:21 +00:00
|
|
|
:type 'string
|
|
|
|
:group 'org-babel)
|
|
|
|
|
2021-11-13 21:51:56 +00:00
|
|
|
(defcustom ob-clojure-babashka-command (executable-find "bb")
|
2023-03-09 15:11:27 +00:00
|
|
|
"Babashka command used by the Clojure `babashka' backend."
|
2022-12-01 11:40:28 +00:00
|
|
|
:type '(choice file (const nil))
|
2022-11-13 07:29:15 +00:00
|
|
|
:group 'org-babel
|
|
|
|
:package-version '(Org . "9.6"))
|
2021-11-13 21:51:56 +00:00
|
|
|
|
2023-03-09 15:11:27 +00:00
|
|
|
(defcustom ob-clojure-nbb-command (or (executable-find "nbb")
|
2024-10-24 09:04:40 +00:00
|
|
|
(when-let* ((npx (executable-find "npx")))
|
2023-03-09 15:11:27 +00:00
|
|
|
(concat npx " nbb")))
|
|
|
|
"Nbb command used by the ClojureScript `nbb' backend."
|
|
|
|
:type '(choice string (const nil))
|
2022-11-13 07:29:15 +00:00
|
|
|
:group 'org-babel
|
2023-03-09 15:11:27 +00:00
|
|
|
:package-version '(Org . "9.7"))
|
2021-11-13 21:51:56 +00:00
|
|
|
|
2024-10-24 09:04:40 +00:00
|
|
|
(defcustom ob-clojure-cli-command (when-let* ((cmd (executable-find "clojure")))
|
2023-03-09 15:11:27 +00:00
|
|
|
(concat cmd " -M"))
|
|
|
|
"Clojure CLI command used by the Clojure `clojure-cli' backend."
|
2024-06-15 14:45:54 +00:00
|
|
|
:type '(choice string (const nil))
|
2023-03-09 15:11:27 +00:00
|
|
|
:group 'org-babel
|
|
|
|
:package-version '(Org . "9.7"))
|
|
|
|
|
|
|
|
(defun org-babel-expand-body:clojure (body params &optional cljs-p)
|
|
|
|
"Expand BODY according to PARAMS, return the expanded body.
|
|
|
|
When CLJS-P is non-nil, expand in a cljs context instead of clj."
|
2015-10-29 19:26:11 +00:00
|
|
|
(let* ((vars (org-babel--get-vars params))
|
2022-10-12 09:27:58 +00:00
|
|
|
(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"))))
|
2018-03-26 03:35:21 +00:00
|
|
|
(ns (or (cdr (assq :ns params))
|
2020-02-17 01:37:55 +00:00
|
|
|
(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)))
|
2016-09-22 17:45:15 +00:00
|
|
|
(result-params (cdr (assq :result-params params)))
|
2018-03-26 03:35:21 +00:00
|
|
|
(print-level nil)
|
|
|
|
(print-length nil)
|
2019-01-10 01:34:39 +00:00
|
|
|
(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)
|
2024-10-18 10:00:54 +00:00
|
|
|
;; Remove comments, they break (let [...] ...) bindings
|
|
|
|
(let ((body (replace-regexp-in-string "^[ ]*;+.*$" "" body)))
|
|
|
|
(format "(let [%s]\n%s)"
|
2019-01-10 01:34:39 +00:00
|
|
|
(mapconcat
|
|
|
|
(lambda (var)
|
2022-10-27 14:04:02 +00:00
|
|
|
(format "%S '%S" (car var) (cdr var)))
|
2019-01-10 01:34:39 +00:00
|
|
|
vars
|
|
|
|
"\n ")
|
2024-10-18 10:00:54 +00:00
|
|
|
body)))))))
|
2023-03-09 15:11:27 +00:00
|
|
|
;; 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)
|
|
|
|
body
|
|
|
|
|
|
|
|
;; If the result is not "output" (i.e. it's "value"), disable
|
|
|
|
;; stdout output and print the last returned value. Use pprint
|
|
|
|
;; instead of prn when results param is "pp" or "code".
|
|
|
|
(concat
|
|
|
|
(if (or (member "code" result-params)
|
|
|
|
(member "pp" result-params))
|
|
|
|
(concat (if cljs-p
|
|
|
|
"(require '[cljs.pprint :refer [pprint]])"
|
|
|
|
"(require '[clojure.pprint :refer [pprint]])")
|
|
|
|
" (pprint ")
|
|
|
|
"(prn ")
|
|
|
|
(if cljs-p
|
|
|
|
"(binding [cljs.core/*print-fn* (constantly nil)]"
|
|
|
|
"(binding [*out* (java.io.StringWriter.)]")
|
|
|
|
body "))"))))
|
2010-04-11 20:29:24 +00:00
|
|
|
|
2020-02-17 01:37:55 +00:00
|
|
|
(defvar ob-clojure-inf-clojure-filter-out)
|
|
|
|
(defvar ob-clojure-inf-clojure-tmp-output)
|
2020-02-16 10:16:00 +00:00
|
|
|
(defun ob-clojure-inf-clojure-output (s)
|
|
|
|
"Store a trimmed version of S in a variable and return S."
|
2020-02-16 22:43:56 +00:00
|
|
|
(let ((s0 (org-trim
|
|
|
|
(replace-regexp-in-string
|
2020-02-17 01:37:55 +00:00
|
|
|
ob-clojure-inf-clojure-filter-out "" s))))
|
2020-02-16 10:16:00 +00:00
|
|
|
(push s0 ob-clojure-inf-clojure-tmp-output))
|
|
|
|
s)
|
|
|
|
|
2020-02-16 22:43:56 +00:00
|
|
|
(defmacro ob-clojure-with-temp-expanded (expanded params &rest body)
|
|
|
|
"Run BODY on EXPANDED code block with PARAMS."
|
|
|
|
(declare (debug (body)) (indent 2))
|
|
|
|
`(with-temp-buffer
|
|
|
|
(insert ,expanded)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (not (looking-at "\\s-*\\'"))
|
|
|
|
(let* ((beg (point))
|
|
|
|
(end (progn (forward-sexp) (point)))
|
|
|
|
(exp (org-babel-expand-body:clojure
|
|
|
|
(buffer-substring beg end) ,params)))
|
|
|
|
(sit-for .1)
|
|
|
|
,@body))))
|
|
|
|
|
|
|
|
(defsubst ob-clojure-string-or-list (l)
|
|
|
|
"Convert list L into a string or a list of list."
|
|
|
|
(if (and (listp l) (= (length l) 1))
|
|
|
|
(car l)
|
|
|
|
(mapcar #'list l)))
|
|
|
|
|
2020-02-16 10:16:00 +00:00
|
|
|
(defvar inf-clojure-buffer)
|
2020-02-17 01:37:55 +00:00
|
|
|
(defvar comint-prompt-regexp)
|
2020-02-16 10:16:00 +00:00
|
|
|
(defvar inf-clojure-comint-prompt-regexp)
|
2020-02-16 22:43:56 +00:00
|
|
|
(defun ob-clojure-eval-with-inf-clojure (expanded params)
|
|
|
|
"Evaluate EXPANDED code block with PARAMS using inf-clojure."
|
2023-01-23 15:06:46 +00:00
|
|
|
(org-require-package 'inf-clojure)
|
2020-02-16 22:43:56 +00:00
|
|
|
;; Maybe initiate the inf-clojure session
|
|
|
|
(unless (and inf-clojure-buffer
|
|
|
|
(buffer-live-p (get-buffer inf-clojure-buffer)))
|
|
|
|
(save-window-excursion
|
|
|
|
(let* ((alias (cdr (assq :alias params)))
|
|
|
|
(cmd0 (inf-clojure-cmd (inf-clojure-project-type)))
|
|
|
|
(cmd (if alias (replace-regexp-in-string
|
|
|
|
"clojure" (format "clojure -A%s" alias)
|
|
|
|
cmd0)
|
|
|
|
cmd0)))
|
2024-06-30 18:36:25 +00:00
|
|
|
(setq-local
|
|
|
|
org-babel-comint-prompt-regexp-fallback comint-prompt-regexp
|
2024-01-22 11:55:09 +00:00
|
|
|
comint-prompt-regexp inf-clojure-comint-prompt-regexp)
|
2020-02-16 22:43:56 +00:00
|
|
|
(funcall-interactively #'inf-clojure cmd)
|
|
|
|
(goto-char (point-max))))
|
2020-02-17 01:37:55 +00:00
|
|
|
(sit-for 1))
|
2020-02-16 22:43:56 +00:00
|
|
|
;; Now evaluate the code
|
2020-02-17 01:37:55 +00:00
|
|
|
(setq ob-clojure-inf-clojure-filter-out
|
|
|
|
(concat "^nil\\|nil$\\|\\s-*"
|
|
|
|
(or (cdr (assq :ns params))
|
|
|
|
org-babel-clojure-default-ns)
|
|
|
|
"=>\\s-*"))
|
2020-02-16 22:43:56 +00:00
|
|
|
(add-hook 'comint-preoutput-filter-functions
|
|
|
|
#'ob-clojure-inf-clojure-output)
|
|
|
|
(setq ob-clojure-inf-clojure-tmp-output nil)
|
|
|
|
(ob-clojure-with-temp-expanded expanded nil
|
|
|
|
(inf-clojure-eval-string exp))
|
|
|
|
(sit-for .5)
|
|
|
|
(remove-hook 'comint-preoutput-filter-functions
|
|
|
|
#'ob-clojure-inf-clojure-output)
|
|
|
|
;; And return the result
|
|
|
|
(ob-clojure-string-or-list
|
|
|
|
(delete nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (s)
|
|
|
|
(unless (or (equal "" s)
|
|
|
|
(string-match-p "^Clojure" s))
|
|
|
|
s))
|
|
|
|
(reverse ob-clojure-inf-clojure-tmp-output)))))
|
|
|
|
|
2023-03-19 20:39:07 +00:00
|
|
|
(defun ob-clojure-eval-with-cider (expanded _params &optional cljs-p)
|
2023-03-23 12:25:15 +00:00
|
|
|
"Evaluate EXPANDED code block using cider.
|
|
|
|
When CLJS-P is non-nil, use a cljs connection instead of clj.
|
|
|
|
The PARAMS from Babel are not used in this function."
|
2023-01-23 15:06:46 +00:00
|
|
|
(org-require-package 'cider "Cider")
|
2023-03-09 15:11:27 +00:00
|
|
|
(let ((connection (cider-current-connection (if cljs-p "cljs" "clj"))))
|
2020-02-16 22:43:56 +00:00
|
|
|
(unless connection (sesman-start-session 'CIDER))
|
|
|
|
(if (not connection)
|
|
|
|
;; Display in the result instead of using `user-error'
|
2023-03-09 15:11:27 +00:00
|
|
|
"Please reevaluate when nREPL is connected"
|
|
|
|
(let ((response (nrepl-sync-request:eval expanded connection)))
|
|
|
|
(or (nrepl-dict-get response "root-ex")
|
|
|
|
(nrepl-dict-get response "ex")
|
|
|
|
(nrepl-dict-get response "out"))))))
|
2020-02-16 22:43:56 +00:00
|
|
|
|
|
|
|
(defun ob-clojure-eval-with-slime (expanded params)
|
|
|
|
"Evaluate EXPANDED code block with PARAMS using slime."
|
2023-01-23 15:06:46 +00:00
|
|
|
(org-require-package 'slime "SLIME")
|
2020-02-16 22:43:56 +00:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert expanded)
|
|
|
|
(slime-eval
|
|
|
|
`(swank:eval-and-grab-output
|
|
|
|
,(buffer-substring-no-properties (point-min) (point-max)))
|
|
|
|
(cdr (assq :package params)))))
|
|
|
|
|
2023-03-09 15:11:27 +00:00
|
|
|
(defun ob-clojure-eval-with-cmd (cmd expanded)
|
|
|
|
"Evaluate EXPANDED code block using CMD (babashka, clojure or nbb)."
|
|
|
|
(let ((script-file (org-babel-temp-file "clojure-cmd-script-" ".clj")))
|
2021-11-13 21:51:56 +00:00
|
|
|
(with-temp-file script-file
|
|
|
|
(insert expanded))
|
|
|
|
(org-babel-eval
|
2023-03-09 15:11:27 +00:00
|
|
|
(format "%s %s" cmd (org-babel-process-file-name script-file))
|
2021-11-13 21:51:56 +00:00
|
|
|
"")))
|
|
|
|
|
2023-03-09 15:11:27 +00:00
|
|
|
(defun org-babel-execute:clojure (body params &optional cljs-p)
|
|
|
|
"Execute the BODY block of Clojure code with PARAMS using Babel.
|
|
|
|
When CLJS-P is non-nil, execute with a ClojureScript backend
|
|
|
|
instead of Clojure."
|
2022-10-08 09:41:20 +00:00
|
|
|
(let* ((backend-override (cdr (assq :backend params)))
|
|
|
|
(org-babel-clojure-backend
|
|
|
|
(cond
|
|
|
|
(backend-override (intern backend-override))
|
2023-03-09 15:11:27 +00:00
|
|
|
(org-babel-clojure-backend (if cljs-p
|
|
|
|
org-babel-clojurescript-backend
|
|
|
|
org-babel-clojure-backend))
|
|
|
|
(t (user-error "You need to customize `%S'
|
|
|
|
or set the `:backend' header argument"
|
|
|
|
(if cljs-p
|
|
|
|
org-babel-clojurescript-backend
|
|
|
|
org-babel-clojure-backend)))))
|
|
|
|
;; We allow a Clojure source block to be evaluated with the
|
|
|
|
;; nbb backend and therefore have to expand the body with
|
|
|
|
;; ClojureScript syntax when we either evaluate a
|
|
|
|
;; ClojureScript source block or use the nbb backend.
|
|
|
|
(cljs-p (or cljs-p (eq org-babel-clojure-backend 'nbb))))
|
|
|
|
(let* ((expanded (org-babel-expand-body:clojure body params cljs-p))
|
2022-10-08 09:41:20 +00:00
|
|
|
(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))
|
2023-03-09 15:11:27 +00:00
|
|
|
((eq org-babel-clojure-backend 'clojure-cli)
|
|
|
|
(ob-clojure-eval-with-cmd ob-clojure-cli-command expanded))
|
2022-10-08 09:41:20 +00:00
|
|
|
((eq org-babel-clojure-backend 'babashka)
|
2023-03-09 15:11:27 +00:00
|
|
|
(ob-clojure-eval-with-cmd ob-clojure-babashka-command expanded))
|
2022-10-08 09:41:20 +00:00
|
|
|
((eq org-babel-clojure-backend 'nbb)
|
2023-03-09 15:11:27 +00:00
|
|
|
(ob-clojure-eval-with-cmd ob-clojure-nbb-command expanded))
|
2022-10-08 09:41:20 +00:00
|
|
|
((eq org-babel-clojure-backend 'cider)
|
2023-03-09 15:11:27 +00:00
|
|
|
(ob-clojure-eval-with-cider expanded params cljs-p))
|
2022-10-08 09:41:20 +00:00
|
|
|
((eq org-babel-clojure-backend 'slime)
|
2023-03-09 15:11:27 +00:00
|
|
|
(ob-clojure-eval-with-slime expanded params))
|
|
|
|
(t (user-error "Invalid backend"))))
|
2022-10-08 09:41:20 +00:00
|
|
|
(org-babel-result-cond result-params
|
|
|
|
result
|
|
|
|
(condition-case nil (org-babel-script-escape result)
|
|
|
|
(error result))))))
|
2013-10-03 16:23:16 +00:00
|
|
|
|
2020-02-13 15:18:32 +00:00
|
|
|
(defun org-babel-execute:clojurescript (body params)
|
2020-02-16 22:43:56 +00:00
|
|
|
"Evaluate BODY with PARAMS as ClojureScript code."
|
2023-03-09 15:11:27 +00:00
|
|
|
(org-babel-execute:clojure body params t))
|
2020-02-13 15:18:32 +00:00
|
|
|
|
2010-06-11 23:02:42 +00:00
|
|
|
(provide 'ob-clojure)
|
2010-06-25 16:32:35 +00:00
|
|
|
|
2010-06-11 23:02:42 +00:00
|
|
|
;;; ob-clojure.el ends here
|