From: stardiviner <numbchild@gmail.com>
To: org-mode <emacs-orgmode@gnu.org>
Subject: [PATCH] add :session support for ob-js.el
Date: Mon, 12 Mar 2018 17:02:26 +0800 [thread overview]
Message-ID: <4f31b760-06ac-5c32-8dbd-76f1017d3cd1@gmail.com> (raw)
[-- 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
next reply other threads:[~2018-03-12 9:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 9:02 stardiviner [this message]
2018-03-13 8:43 ` [PATCH] add :session support for ob-js.el 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
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f31b760-06ac-5c32-8dbd-76f1017d3cd1@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 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).