mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-22 07:09:47 +00:00
babel: ruby: New variable assignment and expansion scheme
* ob-ruby.el (org-babel-execute:ruby): Use generic expansion function (org-babel-prep-session:ruby): Use new variable assignment function (org-babel-variable-assignments:ruby): New function (org-babel-expand-body:ruby): Delete function
This commit is contained in:
parent
2699f4e9bc
commit
2fc9b08a23
@ -52,17 +52,6 @@
|
||||
(defvar org-babel-ruby-command "ruby"
|
||||
"Name of command to use for executing ruby code.")
|
||||
|
||||
(defun org-babel-expand-body:ruby (body params)
|
||||
"Expand BODY according to PARAMS, return the expanded body."
|
||||
(let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
|
||||
(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'."
|
||||
@ -70,7 +59,8 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(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))
|
||||
(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))
|
||||
@ -85,13 +75,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
"Prepare SESSION according to the header arguments specified in PARAMS."
|
||||
;; (message "params=%S" params) ;; debugging
|
||||
(let* ((session (org-babel-ruby-initiate-session session))
|
||||
(vars (mapcar #'cdr (org-babel-get-header params :var)))
|
||||
(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)
|
||||
@ -111,6 +95,15 @@ This function is called by `org-babel-execute-src-block'."
|
||||
|
||||
;; 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
|
||||
|
Loading…
Reference in New Issue
Block a user