I added org-mode babel ob-js.el header argument :session.
Following packages :session are supported: - skewer-mode - js-comint - Indium
>From 2cdf05cf2fe3e0740997d9861c8ff8f81c163750 Mon Sep 17 00:00:00 2001 From: stardiviner <numbch...@gmail.com> Date: Fri, 9 Mar 2018 00:10:54 +0800 Subject: [PATCH 3/3] * ob-js.el: add :session support with js-comint. --- lisp/ob-js.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/ob-js.el b/lisp/ob-js.el index d2fc5e29c..126685813 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -59,6 +59,7 @@ :version "24.1" :type '(choice (const "node") (const "mozrepl") + (const "js-comint") (const "skewer-mode")) :safe #'stringp) @@ -159,7 +160,17 @@ specifying a variable of the same value." then create. Return the initialized session." (unless (string= session "none") (cond - ((string= "*skewer-repl*" session) + ((and (string= "js-comint" org-babel-js-cmd) ; `js-comint' + (string= "*Javascript REPL*" session)) + (require 'js-comint) + (let ((session-buffer "*Javascript REPL*")) + (if (and (org-babel-comint-buffer-livep (get-buffer session-buffer)) + (comint-check-proc session-buffer)) + session-buffer + (call-interactively 'run-js) + (sit-for .5) + session-buffer))) + ((string= "*skewer-repl*" session) ; `skewer-mode' (require 'skewer-repl) (let ((session-buffer (get-buffer "*skewer-repl*"))) (if (and (org-babel-comint-buffer-livep (get-buffer session-buffer)) -- 2.16.2
>From 4eef9f4fc9534ac45b5d98ba8eab36f764cd7518 Mon Sep 17 00:00:00 2001 From: stardiviner <numbch...@gmail.com> Date: Thu, 8 Mar 2018 23:15:16 +0800 Subject: [PATCH 2/3] * ob-js.el: support :session for Indium Node.js REPL. --- lisp/ob-js.el | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lisp/ob-js.el b/lisp/ob-js.el index e2a2a9cec..d2fc5e29c 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -70,21 +70,30 @@ "Execute a block of Javascript code with org-babel. This function is called by `org-babel-execute-src-block'" (let* ((org-babel-js-cmd (or (cdr (assq :cmd params)) org-babel-js-cmd)) + (session (cdr (assq :session params))) (result-type (cdr (assq :result-type params))) (full-body (org-babel-expand-body:generic body params (org-babel-variable-assignments:js params))) (result (if (not (string= (cdr (assq :session params)) "none")) ;; session evaluation - (let ((session (org-babel-prep-session:js - (cdr (assq :session params)) params))) - (nth 1 - (org-babel-comint-with-output - (session (format "%S" org-babel-js-eoe) t body) - (mapc - (lambda (line) - (insert (org-babel-chomp line)) - (comint-send-input nil t)) - (list body (format "%S" org-babel-js-eoe)))))) + (cond + ;; Indium Node + ((string= "*JS REPL*" session) + (require 'indium-repl) + (unless (get-buffer session) + (indium-run-node)) + (indium-eval full-body)) + (t + (let ((session (org-babel-prep-session:js + (cdr (assq :session params)) params))) + (nth 1 + (org-babel-comint-with-output + (session (format "%S" org-babel-js-eoe) t body) + (mapc ; FIXME: stack on this scope when `skewer-eval' + (lambda (line) + (insert (org-babel-chomp line)) + (comint-send-input nil t)) + (list body (format "%S" org-babel-js-eoe)))))))) ;; external evaluation (let ((script-file (org-babel-temp-file "js-script-"))) (with-temp-file script-file -- 2.16.2
>From 9c3a57107e4ed598ca24582fa330fe698829b61e Mon Sep 17 00:00:00 2001 From: stardiviner <numbch...@gmail.com> Date: Thu, 8 Mar 2018 17:15:58 +0800 Subject: [PATCH] * ob-js.el: support use skewer-mode as session support. --- lisp/ob-js.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lisp/ob-js.el b/lisp/ob-js.el index 38c8c39ac..e2a2a9cec 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -27,6 +27,11 @@ ;; ;; This certainly isn't optimally robust, but it seems to be working ;; for the basic use cases. +;; +;; `skewer-mode' session support: +;; #+begin_src js :session *skewer-repl* +;; console.log("chris"); +;; #+end_src ;;; Requirements: @@ -52,7 +57,10 @@ "Name of command used to evaluate js blocks." :group 'org-babel :version "24.1" - :type 'string) + :type '(choice (const "node") + (const "mozrepl") + (const "skewer-mode")) + :safe #'stringp) (defvar org-babel-js-function-wrapper "require('sys').print(require('sys').inspect(function(){\n%s\n}()));" @@ -142,6 +150,18 @@ specifying a variable of the same value." then create. Return the initialized session." (unless (string= session "none") (cond + ((string= "*skewer-repl*" session) + (require 'skewer-repl) + (let ((session-buffer (get-buffer "*skewer-repl*"))) + (if (and (org-babel-comint-buffer-livep (get-buffer session-buffer)) + (comint-check-proc session-buffer)) + session-buffer + ;; start skewer REPL. + (sit-for .5) + (httpd-start) + (run-skewer) + (sit-for .5) + session-buffer))) ((string= "mozrepl" org-babel-js-cmd) (require 'moz) (let ((session-buffer (save-window-excursion -- 2.16.2