From: stardiviner <numbchild@gmail.com>
To: org-mode <emacs-orgmode@gnu.org>
Subject: [PATCH] migrate ob-clojure initiate session code from ob-clojure-literate.el into ob-clojure.el
Date: Thu, 19 Apr 2018 18:22:32 +0800 [thread overview]
Message-ID: <87a7tza42f.fsf@gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2018-04-19 10:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 10:22 stardiviner [this message]
2018-04-20 8:59 ` [PATCH] migrate ob-clojure initiate session code from ob-clojure-literate.el into ob-clojure.el 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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a7tza42f.fsf@gmail.com \
--to=numbchild@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.