Mercurial > emacs
diff lisp/org/ob-ruby.el @ 111506:5cb272c831e8
Install org-mode version 7.3
author | Carsten Dominik <carsten.dominik@gmail.com> |
---|---|
date | Thu, 11 Nov 2010 22:10:19 -0600 |
parents | a150e8a14679 |
children | 76c2ff4450eb |
line wrap: on
line diff
--- a/lisp/org/ob-ruby.el Thu Nov 11 19:23:58 2010 -0800 +++ b/lisp/org/ob-ruby.el Thu Nov 11 22:10:19 2010 -0600 @@ -5,7 +5,7 @@ ;; Author: Eric Schulte ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org -;; Version: 7.01 +;; Version: 7.3 ;; This file is part of GNU Emacs. @@ -52,48 +52,30 @@ (defvar org-babel-ruby-command "ruby" "Name of command to use for executing ruby code.") -(defun org-babel-expand-body:ruby (body params &optional processed-params) - "Expand BODY according to PARAMS, return the expanded body." - (require 'inf-ruby) - (let ((vars (nth 1 (or processed-params (org-babel-process-params params))))) - (concat - (mapconcat ;; define any variables - (lambda (pair) - (format "%s=%s" - (car pair) - (org-babel-ruby-var-to-ruby (cdr pair)))) - vars "\n") "\n" body "\n"))) - (defun org-babel-execute:ruby (body params) "Execute a block of Ruby code with Babel. This function is called by `org-babel-execute-src-block'." - (let* ((processed-params (org-babel-process-params params)) - (session (org-babel-ruby-initiate-session (first processed-params))) - (result-params (nth 2 processed-params)) - (result-type (nth 3 processed-params)) - (full-body (org-babel-expand-body:ruby - body params processed-params)) + (let* ((session (org-babel-ruby-initiate-session + (cdr (assoc :session params)))) + (result-params (cdr (assoc :result-params params))) + (result-type (cdr (assoc :result-type params))) + (full-body (org-babel-expand-body:generic + body params (org-babel-variable-assignments:ruby params))) (result (org-babel-ruby-evaluate session full-body result-type result-params))) (or (cdr (assoc :file params)) (org-babel-reassemble-table result - (org-babel-pick-name (nth 4 processed-params) + (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) - (org-babel-pick-name (nth 5 processed-params) + (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))) (defun org-babel-prep-session:ruby (session params) "Prepare SESSION according to the header arguments specified in PARAMS." ;; (message "params=%S" params) ;; debugging (let* ((session (org-babel-ruby-initiate-session session)) - (vars (org-babel-ref-variables params)) - (var-lines (mapcar ;; define any variables - (lambda (pair) - (format "%s=%s" - (car pair) - (org-babel-ruby-var-to-ruby (cdr pair)))) - vars))) + (var-lines (org-babel-variable-assignments:ruby params))) (org-babel-comint-in-buffer session (sit-for .5) (goto-char (point-max)) (mapc (lambda (var) @@ -113,6 +95,15 @@ ;; helper functions +(defun org-babel-variable-assignments:ruby (params) + "Return list of ruby statements assigning the block's variables" + (mapcar + (lambda (pair) + (format "%s=%s" + (car pair) + (org-babel-ruby-var-to-ruby (cdr pair)))) + (mapcar #'cdr (org-babel-get-header params :var)))) + (defun org-babel-ruby-var-to-ruby (var) "Convert VAR into a ruby variable. Convert an elisp value into a string of ruby source code @@ -186,12 +177,13 @@ ;; external process evaluation (case result-type (output (org-babel-eval org-babel-ruby-command body)) - (value (let ((tmp-file (make-temp-file "org-babel-ruby-results-"))) - (org-babel-eval org-babel-ruby-command - (format (if (member "pp" result-params) - org-babel-ruby-pp-wrapper-method - org-babel-ruby-wrapper-method) - body tmp-file)) + (value (let ((tmp-file (org-babel-temp-file "ruby-"))) + (org-babel-eval + org-babel-ruby-command + (format (if (member "pp" result-params) + org-babel-ruby-pp-wrapper-method + org-babel-ruby-wrapper-method) + body (org-babel-process-file-name tmp-file 'noquote))) ((lambda (raw) (if (or (member "code" result-params) (member "pp" result-params)) @@ -221,7 +213,7 @@ (if (or (member "code" result-params) (member "pp" result-params)) results (org-babel-ruby-table-or-string results))) - (let* ((tmp-file (make-temp-file "org-babel-ruby-results-")) + (let* ((tmp-file (org-babel-temp-file "ruby-")) (ppp (or (member "code" result-params) (member "pp" result-params)))) (org-babel-comint-with-output @@ -233,10 +225,12 @@ (append (list body) (if (not ppp) - (list (format org-babel-ruby-f-write tmp-file)) + (list (format org-babel-ruby-f-write + (org-babel-process-file-name tmp-file 'noquote))) (list "results=_" "require 'pp'" "orig_out = $stdout" - (format org-babel-ruby-pp-f-write tmp-file))) + (format org-babel-ruby-pp-f-write + (org-babel-process-file-name tmp-file 'noquote)))) (list org-babel-ruby-eoe-indicator))) (comint-send-input nil t)) (org-babel-eval-read-file tmp-file)))))))