X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/11fdef7d0cf3ef1ce30d1cd09ca9ca9a2b099d20..2393085c9ac30ac7378a39ee77760dfdecd4b509:/lisp/org/ob-js.el diff --git a/lisp/org/ob-js.el b/lisp/org/ob-js.el index 06acfb391b..8d0cf7f2a0 100644 --- a/lisp/org/ob-js.el +++ b/lisp/org/ob-js.el @@ -1,28 +1,25 @@ ;;; ob-js.el --- org-babel functions for Javascript -;; Copyright (C) 2010-2011 Free Software Foundation +;; Copyright (C) 2010-2015 Free Software Foundation, Inc. ;; Author: Eric Schulte ;; Keywords: literate programming, reproducible research, js ;; Homepage: http://orgmode.org -;; Version: 7.4 -;;; License: +;; This file is part of GNU Emacs. -;; This program is free software; you can redistribute it and/or modify +;; GNU Emacs 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, or (at your option) -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -35,16 +32,13 @@ ;; - a non-browser javascript engine such as node.js http://nodejs.org/ ;; or mozrepl http://wiki.github.com/bard/mozrepl/ -;; +;; ;; - for session based evaluation mozrepl and moz.el are required see ;; http://wiki.github.com/bard/mozrepl/emacs-integration for ;; configuration instructions ;;; Code: (require 'ob) -(require 'ob-ref) -(require 'ob-comint) -(require 'ob-eval) (eval-when-compile (require 'cl)) (declare-function run-mozilla "ext:moz" (arg)) @@ -58,6 +52,7 @@ (defcustom org-babel-js-cmd "node" "Name of command used to evaluate js blocks." :group 'org-babel + :version "24.1" :type 'string) (defvar org-babel-js-function-wrapper @@ -70,30 +65,32 @@ This function is called by `org-babel-execute-src-block'" (let* ((org-babel-js-cmd (or (cdr (assoc :cmd params)) org-babel-js-cmd)) (result-type (cdr (assoc :result-type params))) (full-body (org-babel-expand-body:generic - body params (org-babel-variable-assignments:js params)))) - (org-babel-js-read - (if (not (string= (cdr (assoc :session params)) "none")) - ;; session evaluation - (let ((session (org-babel-prep-session:js - (cdr (assoc :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)))))) - ;; external evaluation - (let ((script-file (org-babel-temp-file "js-script-"))) - (with-temp-file script-file - (insert - ;; return the value or the output - (if (string= result-type "value") - (format org-babel-js-function-wrapper full-body) - full-body))) - (org-babel-eval - (format "%s %s" org-babel-js-cmd - (org-babel-process-file-name script-file)) "")))))) + body params (org-babel-variable-assignments:js params))) + (result (if (not (string= (cdr (assoc :session params)) "none")) + ;; session evaluation + (let ((session (org-babel-prep-session:js + (cdr (assoc :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)))))) + ;; external evaluation + (let ((script-file (org-babel-temp-file "js-script-"))) + (with-temp-file script-file + (insert + ;; return the value or the output + (if (string= result-type "value") + (format org-babel-js-function-wrapper full-body) + full-body))) + (org-babel-eval + (format "%s %s" org-babel-js-cmd + (org-babel-process-file-name script-file)) ""))))) + (org-babel-result-cond (cdr (assoc :result-params params)) + result (org-babel-js-read result)))) (defun org-babel-js-read (results) "Convert RESULTS into an appropriate elisp value. @@ -132,7 +129,7 @@ specifying a variable of the same value." session)) (defun org-babel-variable-assignments:js (params) - "Return list of Javascript statements assigning the block's variables" + "Return list of Javascript statements assigning the block's variables." (mapcar (lambda (pair) (format "var %s=%s;" (car pair) (org-babel-js-var-to-js (cdr pair)))) @@ -154,11 +151,12 @@ then create. Return the initialized session." (sit-for .5) (org-babel-js-initiate-session session)))) ((string= "node" org-babel-js-cmd ) - (error "session evaluation with node.js is not supported")) + (error "Session evaluation with node.js is not supported")) (t - (error "sessions are only supported with mozrepl add \":cmd mozrepl\""))))) + (error "Sessions are only supported with mozrepl add \":cmd mozrepl\""))))) (provide 'ob-js) + ;;; ob-js.el ends here