emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] migrate ob-clojure initiate session code from ob-clojure-literate.el into ob-clojure.el
@ 2018-04-19 10:22 stardiviner
  2018-04-20  8:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: stardiviner @ 2018-04-19 10:22 UTC (permalink / raw)
  To: org-mode


[-- Attachment #1.1: Type: text/plain, Size: 38 bytes --]

Those code belongs to ob-clojure.el.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-ob-clojure.el-support-org-babel-initiate-session-to-.patch --]
[-- Type: text/x-patch, Size: 5869 bytes --]

From 7306147a55ea29be7a685cd7a92dc158612dfccd Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Thu, 19 Apr 2018 18:16:27 +0800
Subject: [PATCH] * ob-clojure.el: support `org-babel-initiate-session' to
 initialize.

Migrate from ob-clojure-literate.el into ob-clojure.el.
---
 contrib/lisp/ob-clojure-literate.el | 56 -----------------------------
 lisp/ob-clojure.el                  | 55 ++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 56 deletions(-)

diff --git a/contrib/lisp/ob-clojure-literate.el b/contrib/lisp/ob-clojure-literate.el
index e702582d9..ecf786df7 100644
--- a/contrib/lisp/ob-clojure-literate.el
+++ b/contrib/lisp/ob-clojure-literate.el
@@ -185,62 +185,6 @@ If it is a directory, `ob-clojure-literate' will try to create Clojure project a
                  org-babel-default-header-args:clojure)))
     ))
 
-;;; Support `org-babel-initiate-session' / [C-c C-v z] to initialize Clojure session.
-
-(defun org-babel-clojure-initiate-session (&optional session _params)
-  "Initiate a session named SESSION according to PARAMS."
-  (when (and session (not (string= session "none")))
-    (save-window-excursion
-      (unless (org-babel-comint-buffer-livep session)
-        ;; CIDER jack-in to the Clojure project directory.
-        (cond
-         ((eq org-babel-clojure-backend 'cider)
-          (require 'cider)
-          (let ((session-buffer (save-window-excursion
-                                  (cider-jack-in t)
-                                  (current-buffer))))
-            (if (org-babel-comint-buffer-livep session-buffer)
-                (progn (sit-for .25) session-buffer))))
-         ((eq org-babel-clojure-backend 'slime)
-          (error "Session evaluation with SLIME is not supported"))
-         (t
-          (error "Session initiate failed")))
-        )
-      (get-buffer session)
-      )))
-
-(defun org-babel-prep-session:clojure (session params)
-  "Prepare SESSION according to the header arguments specified in PARAMS."
-  (let* ((session (org-babel-clojure-initiate-session session))
-         (var-lines (org-babel-variable-assignments:clojure params)))
-    (when session
-      (org-babel-comint-in-buffer session
-        (mapc (lambda (var)
-                (insert var) (comint-send-input nil t)
-		(org-babel-comint-wait-for-output session)
-		(sit-for .1) (goto-char (point-max))) var-lines)))
-    session))
-
-(defun org-babel-clojure-var-to-clojure (var)
-  "Convert src block's `VAR' to Clojure variable."
-  (if (listp var)
-      (replace-regexp-in-string "(" "'(" var)
-    (cond
-     ((stringp var)
-      ;; wrap org-babel passed in header argument value with quote in Clojure.
-      (format "\"%s\"" var))
-     (t
-      (format "%s" var))))
-  )
-
-(defun org-babel-variable-assignments:clojure (params)
-  "Return a list of Clojure statements assigning the block's variables in `PARAMS'."
-  (mapcar
-   (lambda (pair)
-     (format "(def %s %s)"
-             (car pair)
-             (org-babel-clojure-var-to-clojure (cdr pair))))
-   (org-babel--get-vars params)))
 
 ;;; Support header arguments  :results graphics :file "image.png" by inject Clojure code.
 (defun ob-clojure-literate-inject-code (args)
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 93674b552..f647a3282 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -211,6 +211,61 @@ using the :show-process parameter."
       (condition-case nil (org-babel-script-escape result)
 	(error result)))))
 
+(defun org-babel-clojure-initiate-session (&optional session _params)
+  "Initiate a session named SESSION according to PARAMS."
+  (when (and session (not (string= session "none")))
+    (save-window-excursion
+      (unless (org-babel-comint-buffer-livep session)
+        ;; CIDER jack-in to the Clojure project directory.
+        (cond
+         ((eq org-babel-clojure-backend 'cider)
+          (require 'cider)
+          (let ((session-buffer (save-window-excursion
+                                  (cider-jack-in t)
+                                  (current-buffer))))
+            (if (org-babel-comint-buffer-livep session-buffer)
+                (progn (sit-for .25) session-buffer))))
+         ((eq org-babel-clojure-backend 'slime)
+          (error "Session evaluation with SLIME is not supported"))
+         (t
+          (error "Session initiate failed")))
+        )
+      (get-buffer session)
+      )))
+
+(defun org-babel-prep-session:clojure (session params)
+  "Prepare SESSION according to the header arguments specified in PARAMS."
+  (let* ((session (org-babel-clojure-initiate-session session))
+         (var-lines (org-babel-variable-assignments:clojure params)))
+    (when session
+      (org-babel-comint-in-buffer session
+        (mapc (lambda (var)
+                (insert var) (comint-send-input nil t)
+		(org-babel-comint-wait-for-output session)
+		(sit-for .1) (goto-char (point-max))) var-lines)))
+    session))
+
+(defun org-babel-clojure-var-to-clojure (var)
+  "Convert src block's `VAR' to Clojure variable."
+  (if (listp var)
+      (replace-regexp-in-string "(" "'(" var)
+    (cond
+     ((stringp var)
+      ;; wrap org-babel passed in header argument value with quote in Clojure.
+      (format "\"%s\"" var))
+     (t
+      (format "%s" var))))
+  )
+
+(defun org-babel-variable-assignments:clojure (params)
+  "Return a list of Clojure statements assigning the block's variables in `PARAMS'."
+  (mapcar
+   (lambda (pair)
+     (format "(def %s %s)"
+             (car pair)
+             (org-babel-clojure-var-to-clojure (cdr pair))))
+   (org-babel--get-vars params)))
+
 (provide 'ob-clojure)
 
 ;;; ob-clojure.el ends here
-- 
2.17.0


[-- Attachment #1.3: Type: text/plain, Size: 202 bytes --]


-- 
[ stardiviner ] don't need to convince with trends.
       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

end of thread, other threads:[~2018-10-25 23:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-19 10:22 [PATCH] migrate ob-clojure initiate session code from ob-clojure-literate.el into ob-clojure.el stardiviner
2018-04-20  8:59 ` Nicolas Goaziou
2018-10-23 12:02   ` stardiviner
2018-10-24 11:41     ` Nicolas Goaziou
2018-10-25  5:51       ` stardiviner
2018-10-25  8:37         ` Nicolas Goaziou
2018-10-25 23:38           ` stardiviner

Code repositories for project(s) associated with this public 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).