Revert "Basic javascript support via skewer.el"

This reverts commit 9e39797ce7.
This commit is contained in:
John Miller 2016-09-03 18:10:07 -05:00
parent 9e39797ce7
commit 812757fcc3
4 changed files with 9 additions and 101 deletions

View file

@ -74,11 +74,6 @@ nodejs (you understand this difference, right? Right?).
Another thought is to get python to do this for us. The packages [[][naked]] (an
unfortunate name given my corporate firewall) and [[https://github.com/doloopwhile/PyExecJs][PyExecJs]].
I am liking skewer, but worth noting:
1. When connected to multiple clients the same javascript gets sent to each
client.
2. Execute code using ``skewer-eval`` or ``skewer-eval-synchronously``.
** Embedding [[https://github.com/ellisonbg/altair][Altair]] plots
@ -94,17 +89,6 @@ calling from ein all that gets returned is javascript, which
Somehow, when running [[https://nbconvert.readthedocs.io/en/latest/][nbconvert]], the javascript gets turned into a png. How to trigger
that when normally executing cells?
Even being able to execute javascript in the running notebook this will be
difficult to implement as Altair relies on ipywidget using [[http://vega.github.io/vega-lite/usage/embed.html][vega-embed]] to modify
the DOM of the existing document. Not sure if it is possible to bend this to our
will, but vega does have an API that allows for [[https://github.com/vega/vega/wiki/Headless-Mode][headless]] calling.
** Resizing Images
Some control using insert-sliced-image?
Or maybe using the package [[https://github.com/mhayashi1120/Emacs-imagex][emacs-imagex]]? Requires installation of imagemagick.
** Mike DeCandia's Wish and Bug List
*** Wishlist

View file

@ -136,19 +136,12 @@ drawing images. If it is of the form of ``(ROWS COLS)``, it is
passed to the corresponding arguments of `insert-sliced-image'.
.. FIXME: ROWS and COLS must be determined dynamically by measuring
the size of image and Emacs window.
the size of iamge and Emacs window.
See also: https://github.com/tkf/emacs-ipython-notebook/issues/94"
:type 'boolean
:group 'ein)
(defcustom ein:enable-dynamic-javascript nil
"[EXPERIMENTAL] When non-nil enable support in ein for
executing dynamic javascript. This feature requires installation
of the skewer package."
:type 'boolean
:group 'ein)
;;; EIEIO related utils
@ -896,7 +889,7 @@ If END is non-`nil', return the location of next element."
(append (plist-get element :output) (list ewoc-node)))
(ewoc-invalidate ewoc (ein:cell-element-get cell :footer))))
(cl-defmethod ein:cell-append-pyout ((cell ein:codecell) json)
(defmethod ein:cell-append-pyout ((cell ein:codecell) json)
"Insert pyout type output in the buffer.
Called from ewoc pretty printer via `ein:cell-insert-output'."
(ein:insert-read-only (format "Out [%s]:"
@ -923,7 +916,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
(ein:deflocal ein:%cell-append-stream-last-cell% nil
"The last cell in which `ein:cell-append-stream' is used.")
(cl-defmethod ein:cell-append-stream ((cell ein:codecell) json)
(defmethod ein:cell-append-stream ((cell ein:codecell) json)
"Insert stream type output in the buffer.
Called from ewoc pretty printer via `ein:cell-insert-output'."
(unless (plist-get json :stream)
@ -946,15 +939,11 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
(ein:cell-append-text text 'font-lock-face 'ein:cell-output-stderr)
(ein:cell-append-text text)))
(cl-defmethod ein:cell-append-display-data ((cell ein:codecell) json)
(defmethod ein:cell-append-display-data ((cell ein:codecell) json)
"Insert display-data type output in the buffer.
Called from ewoc pretty printer via `ein:cell-insert-output'."
(if (and (plist-get json :javascript)
(oref cell :dynamic) ein:enable-dynamic-javascript)
(ein:execute-javascript cell json)
(progn
(ein:cell-append-mime-type json (oref cell :dynamic))
(ein:insert-read-only "\n"))))
(ein:cell-append-mime-type json (oref cell :dynamic))
(ein:insert-read-only "\n"))
(defcustom ein:output-type-preference
(if (and (fboundp 'shr-insert-document)
@ -1009,7 +998,9 @@ prettified text thus be used instead of HTML type."
;; they come out after `text'. Maybe it is better to inform user
;; when one of them is inserted.
((javascript text/javascript)
(ein:log 'warn "Evaluation of dynamic javascript is not enabled.")
(when dynamic
(ein:log 'info (concat "ein:cell-append-mime-type does not support "
"dynamic javascript. got: %s") value))
(ein:insert-read-only (plist-get json type)))
(emacs-lisp
(when dynamic

View file

@ -1,54 +0,0 @@
;;; ein-skewer.el --- Cell module
;; (C) 2016 - John M Miller
;; Author: John M Miller <millejoh at mac.com>
;; This file is NOT part of GNU Emacs.
;; ein-skewer.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; ein-skewre.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with ein-cell.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This depends on the skewer package, so likely will get split into
;; its own package at some point.
;;; Code:
(require 'skewer-mode)
(defvar *ein:skewer-running-p* nil "True if the emacs httpd server has been started.")
(defun ein:js-prepare-result (result type)
(list :output_type type :text result))
(defun ein:update-javascript-output (cell json result)
(let ((val (ein:js-prepare-result
(cdr (assoc 'value result))
(plist-get json :output_type))))
(setf (oref cell :outputs) (list val))
(ein:cell-append-display-data cell val)))
;; Format of result is ((id . STR) (type . STR) (status . STR) (value . STR) (time . FLOAT))
(defun ein:execute-javascript (cell json)
(unless *ein:skewer-running-p*
(run-skewer)
(setq *ein:skewer-running-p* t))
;; Call synchronously is a bit dangerous here - we should maybe come up with a timeout
;; check.
(ein:update-javascript-output cell
json
(skewer-eval-synchronously (plist-get json :javascript))))
(provide 'ein-skewer)

View file

@ -1,13 +0,0 @@
var spec = {"config": {"cell": {"width": 500, "height": 350}}, "mark": "point", "data": {"values": [{"b": 2, "a": "C"}, {"b": 7, "a": "C"}, {"b": 4, "a": "C"}, {"b": 1, "a": "D"}, {"b": 2, "a": "D"}, {"b": 6, "a": "D"}, {"b": 8, "a": "E"}, {"b": 4, "a": "E"}, {"b": 7, "a": "E"}]}};
var selector = "#516dae39-d227-43ac-9730-30e0bfda52ea";
var type = "vega-lite";
var output_area = this;
console.log(spec);
require(['nbextensions/jupyter-vega/index'], function(vega) {
vega.render(selector, spec, type, output_area);
}, function (err) {
if (err.requireType !== 'scripterror') {
throw(err);
}
});