From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: [PATCH] add :session support for ob-js.el Date: Mon, 12 Mar 2018 17:02:26 +0800 Message-ID: <4f31b760-06ac-5c32-8dbd-76f1017d3cd1@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------81488CB27BECD48CE0211373" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evJML-00016w-Hz for emacs-orgmode@gnu.org; Mon, 12 Mar 2018 05:03:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evJMG-0002DE-G8 for emacs-orgmode@gnu.org; Mon, 12 Mar 2018 05:03:09 -0400 Received: from mail-io0-x234.google.com ([2607:f8b0:4001:c06::234]:43067) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evJMG-0002Bm-3t for emacs-orgmode@gnu.org; Mon, 12 Mar 2018 05:03:04 -0400 Received: by mail-io0-x234.google.com with SMTP id l12so10511581ioc.10 for ; Mon, 12 Mar 2018 02:03:03 -0700 (PDT) Received: from [0.0.0.0] ([119.28.89.243]) by smtp.gmail.com with ESMTPSA id k204sm952652iok.30.2018.03.12.02.02.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 02:03:01 -0700 (PDT) Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: org-mode This is a multi-part message in MIME format. --------------81488CB27BECD48CE0211373 Content-Type: multipart/alternative; boundary="------------405709868B8504C0BE5C1EF0" --------------405709868B8504C0BE5C1EF0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I added org-mode babel ob-js.el header argument :session. Following packages :session are supported: - skewer-mode - js-comint - Indium --------------405709868B8504C0BE5C1EF0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

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

Following packages :session are supported:

- skewer-mode

- js-comint

- Indium

--------------405709868B8504C0BE5C1EF0-- --------------81488CB27BECD48CE0211373 Content-Type: text/x-patch; name="0003-ob-js.el-add-session-support-with-js-comint.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0003-ob-js.el-add-session-support-with-js-comint.patch" >From 2cdf05cf2fe3e0740997d9861c8ff8f81c163750 Mon Sep 17 00:00:00 2001 From: stardiviner 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 --------------81488CB27BECD48CE0211373 Content-Type: text/x-patch; name="0002-ob-js.el-support-session-for-Indium-Node.js-REPL.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-ob-js.el-support-session-for-Indium-Node.js-REPL.patch" >From 4eef9f4fc9534ac45b5d98ba8eab36f764cd7518 Mon Sep 17 00:00:00 2001 From: stardiviner 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 --------------81488CB27BECD48CE0211373 Content-Type: text/x-patch; name="0001-ob-js.el-support-use-skewer-mode-as-session-support.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-ob-js.el-support-use-skewer-mode-as-session-support.pat"; filename*1="ch" >From 9c3a57107e4ed598ca24582fa330fe698829b61e Mon Sep 17 00:00:00 2001 From: stardiviner 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 --------------81488CB27BECD48CE0211373--