diff options
author | Dan Davison <davison@stats.ox.ac.uk> | 2010-09-01 21:05:58 -0700 |
---|---|---|
committer | Dan Davison <davison@stats.ox.ac.uk> | 2010-09-01 21:05:58 -0700 |
commit | 2654704a843e7891f04003356536cea7887711aa (patch) | |
tree | 6b8bd1bbdbe9357a00c56e75850c7d3c2540cf91 | |
parent | d9ca67496fedbb43b2f4be6057c3a2692428302e (diff) | |
parent | 02e6ee37d337fe56f2c5e23f2577b77578813381 (diff) | |
download | org-mode-2654704a843e7891f04003356536cea7887711aa.tar.gz |
Merge branch 'master' of git://repo.or.cz/org-mode
-rw-r--r-- | lisp/ob-ditaa.el | 15 | ||||
-rw-r--r-- | lisp/ob-js.el | 64 | ||||
-rw-r--r-- | lisp/org.el | 2 |
3 files changed, 68 insertions, 13 deletions
diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el index cc95765..20cc192 100644 --- a/lisp/ob-ditaa.el +++ b/lisp/ob-ditaa.el @@ -50,15 +50,18 @@ (defun org-babel-execute:ditaa (body params) "Execute a block of Ditaa code with org-babel. This function is called by `org-babel-execute-src-block'." - (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) - (out-file (cdr (assoc :file params))) - (cmdline (cdr (assoc :cmdline params))) - (in-file (org-babel-temp-file "ditaa-"))) + (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (out-file (cdr (assoc :file params))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (org-babel-temp-file "ditaa-")) + (cmd (concat "java -jar " + (shell-quote-argument + (expand-file-name org-ditaa-jar-path)) + " " cmdline " " in-file " " out-file))) (unless (file-exists-p org-ditaa-jar-path) (error "Could not find ditaa.jar at %s" org-ditaa-jar-path)) (with-temp-file in-file (insert body)) - (message (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file)) - (shell-command (concat "java -jar " (shell-quote-argument org-ditaa-jar-path) " " cmdline " " in-file " " out-file)) + (message cmd) (shell-command cmd) out-file)) (defun org-babel-prep-session:ditaa (session params) diff --git a/lisp/ob-js.el b/lisp/ob-js.el index 9c48552..a59a134 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -33,15 +33,28 @@ ;;; Requirements: -;; node.js | http://nodejs.org/ +;; - 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)) (defvar org-babel-default-header-args:js '() "Default header arguments for js code blocks.") +(defvar org-babel-js-eoe "org-babel-js-eoe" + "String to indicate that evaluation has completed.") + (defcustom org-babel-js-cmd "node" "Name of command used to evaluate js blocks." :group 'org-babel @@ -64,12 +77,22 @@ "Execute a block of Javascript code with org-babel. This function is called by `org-babel-execute-src-block'" (let* ((processed-params (org-babel-process-params params)) - (session (not (string= (nth 0 processed-params) "none"))) + (org-babel-js-cmd (or (cdr (assoc :cmd params)) org-babel-js-cmd)) (result-type (nth 3 processed-params)) (full-body (org-babel-expand-body:js body params processed-params))) (org-babel-js-read - (if session - (error "javascript sessions are not yet supported.") + (if (not (string= (nth 0 processed-params) "none")) + ;; session evaluation + (let ((session (org-babel-prep-session:js + (nth 0 processed-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 @@ -104,12 +127,41 @@ specifying a variable of the same value." (defun org-babel-prep-session:js (session params) "Prepare SESSION according to the header arguments specified in PARAMS." - (error "not yet implemented")) + (let* ((session (org-babel-js-initiate-session session)) + (vars (org-babel-ref-variables params)) + (var-lines + (mapcar + (lambda (pair) (format "var %s=%s;" + (car pair) (org-babel-js-var-to-js (cdr pair)))) + vars))) + (when session + (org-babel-comint-in-buffer session + (sit-for .5) (goto-char (point-max)) + (mapc (lambda (var) + (insert var) (comint-send-input nil t) + (org-babel-comint-wait-for-output session) + (sit-for .1) (goto-char (point-max))) var-lines))) + session)) (defun org-babel-js-initiate-session (&optional session) "If there is not a current inferior-process-buffer in SESSION then create. Return the initialized session." - (error "Javascript sessions are not yet supported.")) + (unless (string= session "none") + (cond + ((string= "mozrepl" org-babel-js-cmd) + (require 'moz) + (let ((session-buffer (save-window-excursion + (run-mozilla nil) + (rename-buffer session) + (current-buffer)))) + (if (org-babel-comint-buffer-livep session-buffer) + (progn (sit-for .25) session-buffer) + (sit-for .5) + (org-babel-js-initiate-session session)))) + ((string= "node" org-babel-js-cmd ) + (error "session evaluation with node.js is not supported")) + (t + (error "sessions are only supported with mozrepl add \":cmd mozrepl\""))))) (provide 'ob-js) diff --git a/lisp/org.el b/lisp/org.el index 7d47ad1..7be1443 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4429,7 +4429,7 @@ means to push this value onto the list in the variable.") "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie "[ \t]*\\(%s\\)" "\\(?:[ \t]*\\(?:\\[[0-9%%/]+\\]\\)\\)?" ;; stats cookie - "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ \t]*$") + "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?[ \t]*$") org-nl-done-regexp (concat "\n\\*+[ \t]+" "\\(?:" (mapconcat 'regexp-quote org-done-keywords "\\|") |