Browse Source

ob-js: support :session for Indium Node REPL.

* lisp/ob-js.el (org-babel-js-cmd): Add "indium".
(org-babel-execute:js): Handle Indium REPL.
stardiviner 7 years ago
parent
commit
b4e2fed77e
2 changed files with 15 additions and 1 deletions
  1. 4 0
      etc/ORG-NEWS
  2. 11 1
      lisp/ob-js.el

+ 4 - 0
etc/ORG-NEWS

@@ -113,6 +113,10 @@ now sort according to the locale’s collation rules instead of by
 code-point.
 
 ** New features
+*** Add ~:session~ support of ob-js for Indium
+#+begin_src js :session "*JS REPL*"
+console.log("stardiviner")
+#+end_src
 *** Add ~:session~ support of ob-js for skewer-mode
 #+begin_src js :session "*skewer-repl*"
 console.log("stardiviner")

+ 11 - 1
lisp/ob-js.el

@@ -43,6 +43,8 @@
 (declare-function run-mozilla "ext:moz" (arg))
 (declare-function httpd-start "simple-httpd" ())
 (declare-function run-skewer "skewer-mode" ())
+(declare-function indium-run-node "indium-nodejs" (command))
+(declare-function indium-eval "indium-interaction" (string &optional callback))
 
 (defvar org-babel-default-header-args:js '()
   "Default header arguments for js code blocks.")
@@ -56,7 +58,8 @@
   :version "24.1"
   :type '(choice (const "node")
 		 (const "mozrepl")
-		 (const "skewer-mode"))
+		 (const "skewer-mode")
+		 (const "indium"))
   :safe #'stringp)
 
 (defvar org-babel-js-function-wrapper
@@ -84,6 +87,13 @@ This function is called by `org-babel-execute-src-block'"
 		     (org-babel-eval
 		      (format "%s %s" org-babel-js-cmd
 			      (org-babel-process-file-name script-file)) "")))
+		  ;; Indium Node REPL
+		  ;; separate case because Indium REPL is not inherited from comint-mode
+		  ((string= session "*JS REPL*")
+		   (require 'indium-repl)
+		   (unless (get-buffer session)
+		     (indium-run-node))
+		   (indium-eval full-body))
 		  ;; session evaluation
 		  (t
 		   (let ((session (org-babel-prep-session:js