emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] add :session support for ob-js.el
@ 2018-03-12  9:02 stardiviner
  2018-03-13  8:43 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: stardiviner @ 2018-03-12  9:02 UTC (permalink / raw)
  To: org-mode


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

I added org-mode babel ob-js.el header argument :session.

Following packages :session are supported:

- skewer-mode

- js-comint

- Indium


[-- Attachment #1.2: Type: text/html, Size: 1035 bytes --]

[-- Attachment #2: 0003-ob-js.el-add-session-support-with-js-comint.patch --]
[-- Type: text/x-patch, Size: 1410 bytes --]

From 2cdf05cf2fe3e0740997d9861c8ff8f81c163750 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@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


[-- Attachment #3: 0002-ob-js.el-support-session-for-Indium-Node.js-REPL.patch --]
[-- Type: text/x-patch, Size: 2128 bytes --]

From 4eef9f4fc9534ac45b5d98ba8eab36f764cd7518 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@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


[-- Attachment #4: 0001-ob-js.el-support-use-skewer-mode-as-session-support.patch --]
[-- Type: text/x-patch, Size: 1712 bytes --]

From 9c3a57107e4ed598ca24582fa330fe698829b61e Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@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


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

end of thread, other threads:[~2018-03-26  1:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-12  9:02 [PATCH] add :session support for ob-js.el stardiviner
2018-03-13  8:43 ` Nicolas Goaziou
2018-03-13 11:51   ` stardiviner
2018-03-17 11:14     ` Nicolas Goaziou
2018-03-17 17:51       ` About the assignment of FSF papers stardiviner
2018-03-18 16:15         ` Nicolas Goaziou
2018-03-22 18:47           ` stardiviner
2018-03-24 19:02             ` Nicolas Goaziou
2018-03-25  3:31       ` [PATCH] add :session support for ob-js.el stardiviner
2018-03-25 21:09         ` Nicolas Goaziou
2018-03-26  1:40           ` 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).