annotate lisp/org/ob-js.el @ 112382:396b01a20bde

Merge: omit auto-generated aclocal.m4 from repository
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 19 Jan 2011 21:02:52 -0800
parents ef719132ddfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1 ;;; ob-js.el --- org-babel functions for Javascript
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
2
112275
6378d1b57038 Add 2011 to remaining FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 111880
diff changeset
3 ;; Copyright (C) 2010, 2011 Free Software Foundation
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
4
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
5 ;; Author: Eric Schulte
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
6 ;; Keywords: literate programming, reproducible research, js
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
7 ;; Homepage: http://orgmode.org
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
8 ;; Version: 7.4
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
9
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
10 ;;; License:
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
11
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
12 ;; This program is free software; you can redistribute it and/or modify
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
14 ;; the Free Software Foundation; either version 3, or (at your option)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
15 ;; any later version.
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
16 ;;
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
17 ;; This program is distributed in the hope that it will be useful,
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
21 ;;
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
25 ;; Boston, MA 02110-1301, USA.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
26
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
27 ;;; Commentary:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
28
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
29 ;; Now working with SBCL for both session and external evaluation.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
30 ;;
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
31 ;; This certainly isn't optimally robust, but it seems to be working
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
32 ;; for the basic use cases.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
33
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
34 ;;; Requirements:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
35
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
36 ;; - a non-browser javascript engine such as node.js http://nodejs.org/
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
37 ;; or mozrepl http://wiki.github.com/bard/mozrepl/
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
38 ;;
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
39 ;; - for session based evaluation mozrepl and moz.el are required see
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
40 ;; http://wiki.github.com/bard/mozrepl/emacs-integration for
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
41 ;; configuration instructions
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
42
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
43 ;;; Code:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
44 (require 'ob)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
45 (require 'ob-ref)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
46 (require 'ob-comint)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
47 (require 'ob-eval)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
48 (eval-when-compile (require 'cl))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
49
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
50 (declare-function run-mozilla "ext:moz" (arg))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
51
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
52 (defvar org-babel-default-header-args:js '()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
53 "Default header arguments for js code blocks.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
54
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
55 (defvar org-babel-js-eoe "org-babel-js-eoe"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
56 "String to indicate that evaluation has completed.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
57
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
58 (defcustom org-babel-js-cmd "node"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
59 "Name of command used to evaluate js blocks."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
60 :group 'org-babel
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
61 :type 'string)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
62
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
63 (defvar org-babel-js-function-wrapper
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
64 "require('sys').print(require('sys').inspect(function(){%s}()));"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
65 "Javascript code to print value of body.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
66
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
67 (defun org-babel-execute:js (body params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
68 "Execute a block of Javascript code with org-babel.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
69 This function is called by `org-babel-execute-src-block'"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
70 (let* ((org-babel-js-cmd (or (cdr (assoc :cmd params)) org-babel-js-cmd))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
71 (result-type (cdr (assoc :result-type params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
72 (full-body (org-babel-expand-body:generic
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
73 body params (org-babel-variable-assignments:js params))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
74 (org-babel-js-read
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
75 (if (not (string= (cdr (assoc :session params)) "none"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
76 ;; session evaluation
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
77 (let ((session (org-babel-prep-session:js
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
78 (cdr (assoc :session params)) params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
79 (nth 1
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
80 (org-babel-comint-with-output
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
81 (session (format "%S" org-babel-js-eoe) t body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
82 (mapc
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
83 (lambda (line)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
84 (insert (org-babel-chomp line)) (comint-send-input nil t))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
85 (list body (format "%S" org-babel-js-eoe))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
86 ;; external evaluation
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
87 (let ((script-file (org-babel-temp-file "js-script-")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
88 (with-temp-file script-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
89 (insert
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
90 ;; return the value or the output
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
91 (if (string= result-type "value")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
92 (format org-babel-js-function-wrapper full-body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
93 full-body)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
94 (org-babel-eval
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
95 (format "%s %s" org-babel-js-cmd
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
96 (org-babel-process-file-name script-file)) ""))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
97
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
98 (defun org-babel-js-read (results)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
99 "Convert RESULTS into an appropriate elisp value.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
100 If RESULTS look like a table, then convert them into an
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
101 Emacs-lisp table, otherwise return the results as a string."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
102 (org-babel-read
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
103 (if (and (stringp results) (string-match "^\\[.+\\]$" results))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
104 (org-babel-read
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
105 (concat "'"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
106 (replace-regexp-in-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
107 "\\[" "(" (replace-regexp-in-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
108 "\\]" ")" (replace-regexp-in-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
109 ", " " " (replace-regexp-in-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
110 "'" "\"" results))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
111 results)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
112
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
113 (defun org-babel-js-var-to-js (var)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
114 "Convert VAR into a js variable.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
115 Convert an elisp value into a string of js source code
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
116 specifying a variable of the same value."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
117 (if (listp var)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
118 (concat "[" (mapconcat #'org-babel-js-var-to-js var ", ") "]")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
119 (format "%S" var)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
120
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
121 (defun org-babel-prep-session:js (session params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
122 "Prepare SESSION according to the header arguments specified in PARAMS."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
123 (let* ((session (org-babel-js-initiate-session session))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
124 (var-lines (org-babel-variable-assignments:js params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
125 (when session
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
126 (org-babel-comint-in-buffer session
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
127 (sit-for .5) (goto-char (point-max))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
128 (mapc (lambda (var)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
129 (insert var) (comint-send-input nil t)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
130 (org-babel-comint-wait-for-output session)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
131 (sit-for .1) (goto-char (point-max))) var-lines)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
132 session))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
133
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
134 (defun org-babel-variable-assignments:js (params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
135 "Return list of Javascript statements assigning the block's variables"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
136 (mapcar
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
137 (lambda (pair) (format "var %s=%s;"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
138 (car pair) (org-babel-js-var-to-js (cdr pair))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
139 (mapcar #'cdr (org-babel-get-header params :var))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
140
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
141 (defun org-babel-js-initiate-session (&optional session)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
142 "If there is not a current inferior-process-buffer in SESSION
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
143 then create. Return the initialized session."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
144 (unless (string= session "none")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
145 (cond
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
146 ((string= "mozrepl" org-babel-js-cmd)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
147 (require 'moz)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
148 (let ((session-buffer (save-window-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
149 (run-mozilla nil)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
150 (rename-buffer session)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
151 (current-buffer))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
152 (if (org-babel-comint-buffer-livep session-buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
153 (progn (sit-for .25) session-buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
154 (sit-for .5)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
155 (org-babel-js-initiate-session session))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
156 ((string= "node" org-babel-js-cmd )
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
157 (error "session evaluation with node.js is not supported"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
158 (t
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
159 (error "sessions are only supported with mozrepl add \":cmd mozrepl\"")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
160
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
161 (provide 'ob-js)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
162
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
163
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
164 ;;; ob-js.el ends here