From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: stardiviner <numbchild@gmail.com>
Cc: org-mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] migrate ob-clojure initiate session code from ob-clojure-literate.el into ob-clojure.el
Date: Fri, 20 Apr 2018 10:59:40 +0200 [thread overview]
Message-ID: <87o9iegsn7.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87a7tza42f.fsf@gmail.com> (stardiviner's message of "Thu, 19 Apr 2018 18:22:32 +0800")
Hello,
stardiviner <numbchild@gmail.com> writes:
> Those code belongs to ob-clojure.el.
Thank you. Comments follow.
> 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.
ob-clojure.el: Support `org-babel-initiate-session' to initialize.
(no leading star, capitalization)
> Migrate from ob-clojure-literate.el into ob-clojure.el.
You need to expound the commit message. In particular, you need to
specify which functions are new, which are modified.
> +(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)
You can merge the `unless' within the `cond', e.g.,
(cond
((org-babel-comint-buffer-livep session) nil)
...)
> + ;; 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)
> + )))
No dangling parens, please.
> +(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)))
No need for `let*'. `let' is sufficient.
> + (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))
`mapc' + `lambda' -> `dolist', e.g:
(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
(dolist (var var-lines)
(insert var)
(comint-send-input nil t)
(org-babel-comint-wait-for-output session)
(sit-for .1)
(goto-char (point-max)))))
session))
> +(defun org-babel-clojure-var-to-clojure (var)
> + "Convert src block's `VAR' to Clojure variable."
VAR, not `VAR'
> + (if (listp var)
> + (replace-regexp-in-string "(" "'(" var)
> + (cond
You can merge the THEN part of the `if' in the `cond'.
> + ((stringp var)
> + ;; wrap org-babel passed in header argument value with quote in Clojure.
;; Wrap Babel passed-in header argument value with quotes in Cojure.
> + (format "\"%s\"" var))
(format "%S" var)
> + (t
> + (format "%s" var))))
> + )
Dangling parens.
> +(defun org-babel-variable-assignments:clojure (params)
> + "Return a list of Clojure statements assigning the block's variables in `PARAMS'."
PARAMS, not `PARAMS'.
> + (mapcar
> + (lambda (pair)
> + (format "(def %s %s)"
> + (car pair)
> + (org-babel-clojure-var-to-clojure (cdr pair))))
> + (org-babel--get-vars params)))
Would it make sense to add a few tests for this?
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2018-04-20 8:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=87o9iegsn7.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=numbchild@gmail.com \
/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.