diff options
| author | Carsten Dominik | 2010-11-11 22:10:19 -0600 |
|---|---|---|
| committer | Carsten Dominik | 2010-11-11 22:10:19 -0600 |
| commit | afe98dfa700de5cf0493e8bf95b7d894e2734e47 (patch) | |
| tree | 92a812b353bb09c1286e8a44fb552de9f1af3384 /lisp/org/ob-ruby.el | |
| parent | df26e1f58a7e484b7ed500ea48d0e1c49345ffbf (diff) | |
| download | emacs-afe98dfa700de5cf0493e8bf95b7d894e2734e47.tar.gz emacs-afe98dfa700de5cf0493e8bf95b7d894e2734e47.zip | |
Install org-mode version 7.3
Diffstat (limited to 'lisp/org/ob-ruby.el')
| -rw-r--r-- | lisp/org/ob-ruby.el | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/lisp/org/ob-ruby.el b/lisp/org/ob-ruby.el index e557c80ef1a..9a9f21cde60 100644 --- a/lisp/org/ob-ruby.el +++ b/lisp/org/ob-ruby.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: Eric Schulte | 5 | ;; Author: Eric Schulte |
| 6 | ;; Keywords: literate programming, reproducible research | 6 | ;; Keywords: literate programming, reproducible research |
| 7 | ;; Homepage: http://orgmode.org | 7 | ;; Homepage: http://orgmode.org |
| 8 | ;; Version: 7.01 | 8 | ;; Version: 7.3 |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -52,48 +52,30 @@ | |||
| 52 | (defvar org-babel-ruby-command "ruby" | 52 | (defvar org-babel-ruby-command "ruby" |
| 53 | "Name of command to use for executing ruby code.") | 53 | "Name of command to use for executing ruby code.") |
| 54 | 54 | ||
| 55 | (defun org-babel-expand-body:ruby (body params &optional processed-params) | ||
| 56 | "Expand BODY according to PARAMS, return the expanded body." | ||
| 57 | (require 'inf-ruby) | ||
| 58 | (let ((vars (nth 1 (or processed-params (org-babel-process-params params))))) | ||
| 59 | (concat | ||
| 60 | (mapconcat ;; define any variables | ||
| 61 | (lambda (pair) | ||
| 62 | (format "%s=%s" | ||
| 63 | (car pair) | ||
| 64 | (org-babel-ruby-var-to-ruby (cdr pair)))) | ||
| 65 | vars "\n") "\n" body "\n"))) | ||
| 66 | |||
| 67 | (defun org-babel-execute:ruby (body params) | 55 | (defun org-babel-execute:ruby (body params) |
| 68 | "Execute a block of Ruby code with Babel. | 56 | "Execute a block of Ruby code with Babel. |
| 69 | This function is called by `org-babel-execute-src-block'." | 57 | This function is called by `org-babel-execute-src-block'." |
| 70 | (let* ((processed-params (org-babel-process-params params)) | 58 | (let* ((session (org-babel-ruby-initiate-session |
| 71 | (session (org-babel-ruby-initiate-session (first processed-params))) | 59 | (cdr (assoc :session params)))) |
| 72 | (result-params (nth 2 processed-params)) | 60 | (result-params (cdr (assoc :result-params params))) |
| 73 | (result-type (nth 3 processed-params)) | 61 | (result-type (cdr (assoc :result-type params))) |
| 74 | (full-body (org-babel-expand-body:ruby | 62 | (full-body (org-babel-expand-body:generic |
| 75 | body params processed-params)) | 63 | body params (org-babel-variable-assignments:ruby params))) |
| 76 | (result (org-babel-ruby-evaluate | 64 | (result (org-babel-ruby-evaluate |
| 77 | session full-body result-type result-params))) | 65 | session full-body result-type result-params))) |
| 78 | (or (cdr (assoc :file params)) | 66 | (or (cdr (assoc :file params)) |
| 79 | (org-babel-reassemble-table | 67 | (org-babel-reassemble-table |
| 80 | result | 68 | result |
| 81 | (org-babel-pick-name (nth 4 processed-params) | 69 | (org-babel-pick-name (cdr (assoc :colname-names params)) |
| 82 | (cdr (assoc :colnames params))) | 70 | (cdr (assoc :colnames params))) |
| 83 | (org-babel-pick-name (nth 5 processed-params) | 71 | (org-babel-pick-name (cdr (assoc :rowname-names params)) |
| 84 | (cdr (assoc :rownames params))))))) | 72 | (cdr (assoc :rownames params))))))) |
| 85 | 73 | ||
| 86 | (defun org-babel-prep-session:ruby (session params) | 74 | (defun org-babel-prep-session:ruby (session params) |
| 87 | "Prepare SESSION according to the header arguments specified in PARAMS." | 75 | "Prepare SESSION according to the header arguments specified in PARAMS." |
| 88 | ;; (message "params=%S" params) ;; debugging | 76 | ;; (message "params=%S" params) ;; debugging |
| 89 | (let* ((session (org-babel-ruby-initiate-session session)) | 77 | (let* ((session (org-babel-ruby-initiate-session session)) |
| 90 | (vars (org-babel-ref-variables params)) | 78 | (var-lines (org-babel-variable-assignments:ruby params))) |
| 91 | (var-lines (mapcar ;; define any variables | ||
| 92 | (lambda (pair) | ||
| 93 | (format "%s=%s" | ||
| 94 | (car pair) | ||
| 95 | (org-babel-ruby-var-to-ruby (cdr pair)))) | ||
| 96 | vars))) | ||
| 97 | (org-babel-comint-in-buffer session | 79 | (org-babel-comint-in-buffer session |
| 98 | (sit-for .5) (goto-char (point-max)) | 80 | (sit-for .5) (goto-char (point-max)) |
| 99 | (mapc (lambda (var) | 81 | (mapc (lambda (var) |
| @@ -113,6 +95,15 @@ This function is called by `org-babel-execute-src-block'." | |||
| 113 | 95 | ||
| 114 | ;; helper functions | 96 | ;; helper functions |
| 115 | 97 | ||
| 98 | (defun org-babel-variable-assignments:ruby (params) | ||
| 99 | "Return list of ruby statements assigning the block's variables" | ||
| 100 | (mapcar | ||
| 101 | (lambda (pair) | ||
| 102 | (format "%s=%s" | ||
| 103 | (car pair) | ||
| 104 | (org-babel-ruby-var-to-ruby (cdr pair)))) | ||
| 105 | (mapcar #'cdr (org-babel-get-header params :var)))) | ||
| 106 | |||
| 116 | (defun org-babel-ruby-var-to-ruby (var) | 107 | (defun org-babel-ruby-var-to-ruby (var) |
| 117 | "Convert VAR into a ruby variable. | 108 | "Convert VAR into a ruby variable. |
| 118 | Convert an elisp value into a string of ruby source code | 109 | Convert an elisp value into a string of ruby source code |
| @@ -186,12 +177,13 @@ return the value of the last statement in BODY, as elisp." | |||
| 186 | ;; external process evaluation | 177 | ;; external process evaluation |
| 187 | (case result-type | 178 | (case result-type |
| 188 | (output (org-babel-eval org-babel-ruby-command body)) | 179 | (output (org-babel-eval org-babel-ruby-command body)) |
| 189 | (value (let ((tmp-file (make-temp-file "org-babel-ruby-results-"))) | 180 | (value (let ((tmp-file (org-babel-temp-file "ruby-"))) |
| 190 | (org-babel-eval org-babel-ruby-command | 181 | (org-babel-eval |
| 191 | (format (if (member "pp" result-params) | 182 | org-babel-ruby-command |
| 192 | org-babel-ruby-pp-wrapper-method | 183 | (format (if (member "pp" result-params) |
| 193 | org-babel-ruby-wrapper-method) | 184 | org-babel-ruby-pp-wrapper-method |
| 194 | body tmp-file)) | 185 | org-babel-ruby-wrapper-method) |
| 186 | body (org-babel-process-file-name tmp-file 'noquote))) | ||
| 195 | ((lambda (raw) | 187 | ((lambda (raw) |
| 196 | (if (or (member "code" result-params) | 188 | (if (or (member "code" result-params) |
| 197 | (member "pp" result-params)) | 189 | (member "pp" result-params)) |
| @@ -221,7 +213,7 @@ return the value of the last statement in BODY, as elisp." | |||
| 221 | (if (or (member "code" result-params) (member "pp" result-params)) | 213 | (if (or (member "code" result-params) (member "pp" result-params)) |
| 222 | results | 214 | results |
| 223 | (org-babel-ruby-table-or-string results))) | 215 | (org-babel-ruby-table-or-string results))) |
| 224 | (let* ((tmp-file (make-temp-file "org-babel-ruby-results-")) | 216 | (let* ((tmp-file (org-babel-temp-file "ruby-")) |
| 225 | (ppp (or (member "code" result-params) | 217 | (ppp (or (member "code" result-params) |
| 226 | (member "pp" result-params)))) | 218 | (member "pp" result-params)))) |
| 227 | (org-babel-comint-with-output | 219 | (org-babel-comint-with-output |
| @@ -233,10 +225,12 @@ return the value of the last statement in BODY, as elisp." | |||
| 233 | (append | 225 | (append |
| 234 | (list body) | 226 | (list body) |
| 235 | (if (not ppp) | 227 | (if (not ppp) |
| 236 | (list (format org-babel-ruby-f-write tmp-file)) | 228 | (list (format org-babel-ruby-f-write |
| 229 | (org-babel-process-file-name tmp-file 'noquote))) | ||
| 237 | (list | 230 | (list |
| 238 | "results=_" "require 'pp'" "orig_out = $stdout" | 231 | "results=_" "require 'pp'" "orig_out = $stdout" |
| 239 | (format org-babel-ruby-pp-f-write tmp-file))) | 232 | (format org-babel-ruby-pp-f-write |
| 233 | (org-babel-process-file-name tmp-file 'noquote)))) | ||
| 240 | (list org-babel-ruby-eoe-indicator))) | 234 | (list org-babel-ruby-eoe-indicator))) |
| 241 | (comint-send-input nil t)) | 235 | (comint-send-input nil t)) |
| 242 | (org-babel-eval-read-file tmp-file))))))) | 236 | (org-babel-eval-read-file tmp-file))))))) |