1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-27 10:55:04 +00:00

Revert "Moving non-language specific code out of language-specific files."

This reverts commit 0f541a680d.

See commit note for parent commit. Both reversions made for same reason.
This commit is contained in:
Dan Davison 2009-07-08 00:13:07 -04:00
parent 9772adef3e
commit 2bddc5fdf8
5 changed files with 67 additions and 49 deletions

View File

@ -35,18 +35,23 @@
(add-to-list 'org-babel-tangle-langs '("R" "r"))
(defun org-babel-execute:R (session body vars result-type)
(defun org-babel-execute:R (body params)
"Execute a block of R code with org-babel. This function is
called by `org-babel-execute-src-block'."
(message "executing R source code block...")
(save-window-excursion
(let ((augmented-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(org-babel-R-assign-elisp (car pair) (cdr pair)))
vars "\n") "\n" body "\n"))
(session (org-babel-R-initiate-session session)))
(org-babel-R-evaluate session augmented-body result-type))))
(let* ((vars (org-babel-ref-variables params))
(full-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(org-babel-R-assign-elisp (car pair) (cdr pair)))
vars "\n") "\n" body "\n"))
(result-params (split-string (or (cdr (assoc :results params)) "")))
(result-type (cond ((member "output" result-params) 'output)
((member "value" result-params) 'value)
(t 'value)))
(session (org-babel-R-initiate-session (cdr (assoc :session params)))))
(org-babel-R-evaluate session full-body result-type))))
(defun org-babel-prep-session:R (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
@ -115,10 +120,10 @@ last statement in BODY, as elisp."
(last-value-eval
(format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
tmp-file))
(augmented-body (mapconcat #'org-babel-chomp
(full-body (mapconcat #'org-babel-chomp
(list body last-value-eval org-babel-R-eoe-indicator) "\n"))
(raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil
(insert augmented-body) (inferior-ess-send-input)))
(insert full-body) (inferior-ess-send-input)))
(results
(let ((broke nil))
(delete

View File

@ -36,19 +36,24 @@
(add-to-list 'org-babel-tangle-langs '("python" "py" "#!/usr/bin/env python"))
(defun org-babel-execute:python (session body vars result-type)
(defun org-babel-execute:python (body params)
"Execute a block of Python code with org-babel. This function is
called by `org-babel-execute-src-block'."
(message "executing Python source code block")
(let ((augmented-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(format "%s=%s"
(car pair)
(org-babel-python-var-to-python (cdr pair))))
vars "\n") "\n" (org-babel-trim body) "\n")) ;; then the source block body
(session (org-babel-python-initiate-session session)))
(org-babel-python-evaluate session augmented-body result-type)))
(let* ((vars (org-babel-ref-variables params))
(result-params (split-string (or (cdr (assoc :results params)) "")))
(result-type (cond ((member "output" result-params) 'output)
((member "value" result-params) 'value)
(t 'value)))
(full-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(format "%s=%s"
(car pair)
(org-babel-python-var-to-python (cdr pair))))
vars "\n") "\n" (org-babel-trim body) "\n")) ;; then the source block body
(session (org-babel-python-initiate-session (cdr (assoc :session params)))))
(org-babel-python-evaluate session full-body result-type)))
(defun org-babel-prep-session:python (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
@ -152,14 +157,14 @@ last statement in BODY, as elisp."
(with-temp-buffer (insert-file-contents tmp-file) (buffer-string)))))))
;; comint session evaluation
(org-babel-comint-in-buffer buffer
(let* ((augmented-body
(let* ((full-body
(mapconcat
#'org-babel-trim
(list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
(raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
;; for some reason python is fussy, and likes enters after every input
(mapc (lambda (statement) (insert statement) (comint-send-input nil t))
(split-string augmented-body "[\r\n]+"))))
(split-string full-body "[\r\n]+"))))
(results (delete org-babel-python-eoe-indicator
(cdr (member org-babel-python-eoe-indicator
(reverse (mapcar #'org-babel-trim raw)))))))

View File

@ -36,19 +36,24 @@
(add-to-list 'org-babel-tangle-langs '("ruby" "rb" "#!/usr/bin/env ruby"))
(defun org-babel-execute:ruby (session body vars result-type)
(defun org-babel-execute:ruby (body params)
"Execute a block of Ruby code with org-babel. This function is
called by `org-babel-execute-src-block'."
(message "executing Ruby source code block")
(let ((augmented-body (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")) ;; then the source block body
(session (org-babel-ruby-initiate-session session)))
(org-babel-ruby-evaluate session augmented-body result-type)))
(let* ((vars (org-babel-ref-variables params))
(result-params (split-string (or (cdr (assoc :results params)) "")))
(result-type (cond ((member "output" result-params) 'output)
((member "value" result-params) 'value)
(t 'value)))
(full-body (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")) ;; then the source block body
(session (org-babel-ruby-initiate-session (cdr (assoc :session params)))))
(org-babel-ruby-evaluate session full-body result-type)))
(defun org-babel-prep-session:ruby (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
@ -138,12 +143,12 @@ last statement in BODY, as elisp."
(org-babel-ruby-table-or-string
(with-temp-buffer (insert-file-contents tmp-file) (buffer-string)))))))
;; comint session evaluation
(let* ((augmented-body
(let* ((full-body
(mapconcat
#'org-babel-chomp
(list body org-babel-ruby-last-value-eval org-babel-ruby-eoe-indicator) "\n"))
(raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
(insert augmented-body) (comint-send-input nil t)))
(insert full-body) (comint-send-input nil t)))
(results (cdr (member org-babel-ruby-eoe-indicator
(reverse (mapcar #'org-babel-ruby-read-string
(mapcar #'org-babel-trim raw)))))))

View File

@ -36,19 +36,24 @@
(add-to-list 'org-babel-tangle-langs '("sh" "sh" "#!/usr/bin/env sh"))
(defun org-babel-execute:sh (session body vars result-type)
(defun org-babel-execute:sh (body params)
"Execute a block of Shell commands with org-babel. This
function is called by `org-babel-execute-src-block'."
(message "executing Shell source code block")
(let ((augmented-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(format "%s=%s"
(car pair)
(org-babel-sh-var-to-sh (cdr pair))))
vars "\n") "\n" body "\n\n")) ;; then the source block body
(session (org-babel-sh-initiate-session (cdr (assoc :session params)))))
(org-babel-sh-evaluate session augmented-body result-type)))
(let* ((vars (org-babel-ref-variables params))
(result-params (split-string (or (cdr (assoc :results params)) "")))
(result-type (cond ((member "output" result-params) 'output)
((member "value" result-params) 'value)
(t 'value)))
(full-body (concat
(mapconcat ;; define any variables
(lambda (pair)
(format "%s=%s"
(car pair)
(org-babel-sh-var-to-sh (cdr pair))))
vars "\n") "\n" body "\n\n")) ;; then the source block body
(session (org-babel-sh-initiate-session (cdr (assoc :session params)))))
(org-babel-sh-evaluate session full-body result-type)))
(defun org-babel-prep-session:sh (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
@ -138,10 +143,10 @@ last statement in BODY."
(org-babel-import-elisp-from-file tmp-file))))))
;; comint session evaluation
(let* ((tmp-file (make-temp-file "org-babel-sh"))
(augmented-body (mapconcat #'org-babel-chomp
(full-body (mapconcat #'org-babel-chomp
(list body org-babel-sh-eoe-indicator) "\n"))
(raw (org-babel-comint-with-output buffer org-babel-sh-eoe-output nil
(insert augmented-body) (comint-send-input nil t)))
(insert full-body) (comint-send-input nil t)))
(results (cdr (member org-babel-sh-eoe-output
(reverse (mapcar #'org-babel-sh-strip-weird-long-prompt
(mapcar #'org-babel-trim raw)))))))

View File

@ -155,8 +155,6 @@ the header arguments specified at the source code block."
(lang (first info))
(body (second info))
(params (org-combine-plists params (third info)))
(session (cdr (assoc :session params)))
(vars (org-babel-ref-variables params))
(result-params (split-string (or (cdr (assoc :results params)) "")))
(result-type (cond ((member "output" result-params) 'output)
((member "value" result-params) 'value)
@ -167,7 +165,7 @@ the header arguments specified at the source code block."
(unless (member lang org-babel-interpreters)
(error "Language is not in `org-babel-interpreters': %s" lang))
(when arg (setq result-params (cons "silent" result-params)))
(setq result (org-babel-process-result (funcall cmd session body vars result-type) result-type))
(setq result (org-babel-process-result (funcall cmd body params) result-type))
(org-babel-insert-result result result-params)
(case result-type (output nil) (value result))))