mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-28 10:56:57 +00:00
org-babel: language specific files using cleaner parameter passing
This commit is contained in:
parent
082fb84c34
commit
0fa68a53ba
@ -40,7 +40,10 @@
|
||||
called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing R source code block...")
|
||||
(save-window-excursion
|
||||
(let* ((session (org-babel-R-initiate-session session))
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(result-type (fourth processed-params))
|
||||
(session (org-babel-R-initiate-session (first processed-params)))
|
||||
(vars (second processed-params))
|
||||
(column-names-p (cdr (assoc :colnames params)))
|
||||
(out-file (cdr (assoc :file params)))
|
||||
(augmented-body
|
||||
@ -120,8 +123,8 @@ called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(defvar org-babel-R-wrapper-method "main <- function ()\n{\n%s\n}
|
||||
write.table(main(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=%s, quote=FALSE)")
|
||||
|
||||
(defun org-babel-R-evaluate (buffer body result-type column-names-p)
|
||||
"Pass BODY to the R process in BUFFER. If RESULT-TYPE equals
|
||||
(defun org-babel-R-evaluate (session body result-type column-names-p)
|
||||
"Pass BODY to the R process in SESSION. If RESULT-TYPE equals
|
||||
'output then return a list of the outputs of the statements in
|
||||
BODY, if RESULT-TYPE equals 'value then return the value of the
|
||||
last statement in BODY, as elisp."
|
||||
@ -143,7 +146,7 @@ last statement in BODY, as elisp."
|
||||
(org-babel-R-process-value-result
|
||||
(org-babel-import-elisp-from-file out-tmp-file) column-names-p))))
|
||||
;; comint session evaluation
|
||||
(org-babel-comint-in-buffer buffer
|
||||
(org-babel-comint-in-buffer session
|
||||
(let* ((tmp-file (make-temp-file "org-babel-R"))
|
||||
(full-body
|
||||
(case result-type
|
||||
@ -153,7 +156,7 @@ last statement in BODY, as elisp."
|
||||
org-babel-R-eoe-indicator) "\n"))
|
||||
(output
|
||||
(mapconcat #'org-babel-chomp (list body org-babel-R-eoe-indicator) "\n"))))
|
||||
(raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil
|
||||
(raw (org-babel-comint-with-output session org-babel-R-eoe-output nil
|
||||
(insert full-body) (inferior-ess-send-input)))
|
||||
(comint-prompt-regexp
|
||||
(concat "^\\("
|
||||
|
@ -195,14 +195,11 @@ last statement in BODY, as elisp."
|
||||
(org-babel-clojure-evaluate-external-process buffer body result-type)))
|
||||
|
||||
(defun org-babel-execute:clojure (body params)
|
||||
"Execute a block of Clojure code with org-babel. This function
|
||||
is called by `org-babel-execute-src-block' with the following
|
||||
variables pre-set using `multiple-value-bind'.
|
||||
|
||||
(session vars result-params result-type)"
|
||||
|
||||
(let* ((body (org-babel-clojure-build-full-form body vars))
|
||||
(session (org-babel-clojure-initiate-session session)))
|
||||
(org-babel-clojure-evaluate session body result-type)))
|
||||
"Execute a block of Clojure code with org-babel."
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(vars (second processed-params))
|
||||
(body (org-babel-clojure-build-full-form body vars))
|
||||
(session (org-babel-clojure-initiate-session (first processed-params))))
|
||||
(org-babel-clojure-evaluate session body (fourth processed-params))))
|
||||
|
||||
(provide 'org-babel-clojure)
|
||||
|
@ -36,16 +36,20 @@
|
||||
(add-to-list 'org-babel-tangle-langs '("emacs-lisp" "el"))
|
||||
|
||||
(defun org-babel-execute:emacs-lisp (body params)
|
||||
"Execute a block of emacs-lisp code with org-babel. This
|
||||
function is called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
"Execute a block of emacs-lisp code with org-babel."
|
||||
(message "executing emacs-lisp code block...")
|
||||
(save-window-excursion
|
||||
(let ((print-level nil) (print-length nil))
|
||||
(eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(result-params (third processed-params))
|
||||
(vars (second (org-babel-process-params params)))
|
||||
(print-level nil) (print-length nil))
|
||||
(eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var)))
|
||||
vars)
|
||||
,(read (concat "(progn "
|
||||
(if (or (member "code" result-params)
|
||||
(member "pp" result-params))
|
||||
(concat "(pp " body ")") body)
|
||||
")")))))))
|
||||
|
||||
(provide 'org-babel-emacs-lisp)
|
||||
;;; org-babel-emacs-lisp.el ends here
|
||||
|
@ -74,6 +74,7 @@ called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing Gnuplot source code block")
|
||||
(save-window-excursion
|
||||
(let* ((vars (org-babel-gnuplot-process-vars params))
|
||||
(session (cdr (assoc :session params)))
|
||||
(out-file (cdr (assoc :file params)))
|
||||
(term (or (cdr (assoc :term params))
|
||||
(when out-file (file-name-extension out-file))))
|
||||
|
@ -55,13 +55,13 @@
|
||||
(defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
|
||||
|
||||
(defun org-babel-execute:haskell (body params)
|
||||
"Execute a block of Haskell code with org-babel. This function
|
||||
is called by `org-babel-execute-src-block' with the following
|
||||
variables pre-set using `multiple-value-bind'.
|
||||
|
||||
(session vars result-params result-type)"
|
||||
"Execute a block of Haskell code with org-babel."
|
||||
(message "executing haskell source code block")
|
||||
(let* ((full-body (concat
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (first processed-params))
|
||||
(vars (second processed-params))
|
||||
(result-type (fourth processed-params))
|
||||
(full-body (concat
|
||||
(mapconcat
|
||||
(lambda (pair) (format "let %s = %s;" (car pair) (cdr pair)))
|
||||
vars "\n") "\n" body "\n"))
|
||||
|
@ -53,7 +53,7 @@ called by `org-babel-execute-src-block'."
|
||||
(regexp-quote (format "%S" (car pair)))
|
||||
(if (stringp (cdr pair))
|
||||
(cdr pair) (format "%S" (cdr pair)))
|
||||
body))) vars)
|
||||
body))) (second (org-babel-process-params params)))
|
||||
body)
|
||||
|
||||
(defun org-babel-prep-session:latex (session params)
|
||||
|
@ -49,13 +49,11 @@
|
||||
(defvar org-babel-ocaml-eoe-output "org-babel-ocaml-eoe")
|
||||
|
||||
(defun org-babel-execute:ocaml (body params)
|
||||
"Execute a block of Ocaml code with org-babel. This function
|
||||
is called by `org-babel-execute-src-block' with the following
|
||||
variables pre-set using `multiple-value-bind'.
|
||||
|
||||
(session vars result-params result-type)"
|
||||
"Execute a block of Ocaml code with org-babel."
|
||||
(message "executing ocaml source code block")
|
||||
(let* ((full-body (concat
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(vars (second processed-params))
|
||||
(full-body (concat
|
||||
(mapconcat
|
||||
(lambda (pair) (format "let %s = %s;" (car pair) (cdr pair)))
|
||||
vars "\n") "\n" body "\n"))
|
||||
|
@ -39,7 +39,12 @@
|
||||
"Execute a block of Perl code with org-babel. This function is
|
||||
called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing Perl source code block")
|
||||
(let ((full-body (concat
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (first processed-params))
|
||||
(vars (second processed-params))
|
||||
(result-params (third processed-params))
|
||||
(result-type (fourth processed-params))
|
||||
(full-body (concat
|
||||
(mapconcat ;; define any variables
|
||||
(lambda (pair)
|
||||
(format "$%s=%s;"
|
||||
|
@ -40,15 +40,20 @@
|
||||
"Execute a block of Python code with org-babel. This function is
|
||||
called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing Python source code block")
|
||||
(let* ((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 session))
|
||||
(result (org-babel-python-evaluate session full-body result-type)))
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (org-babel-python-initiate-session (first processed-params)))
|
||||
(vars (second processed-params))
|
||||
(result-params (third processed-params))
|
||||
(result-type (fourth processed-params))
|
||||
(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
|
||||
|
||||
(result (org-babel-python-evaluate session full-body result-type)))
|
||||
(or (cdr (assoc :file params)) result)))
|
||||
|
||||
(defun org-babel-prep-session:python (session params)
|
||||
|
@ -50,15 +50,19 @@
|
||||
"Execute a block of Ruby code with org-babel. This function is
|
||||
called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing Ruby source code block")
|
||||
(let* ((full-body (concat
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (org-babel-ruby-initiate-session (first processed-params)))
|
||||
(vars (second processed-params))
|
||||
(result-params (third processed-params))
|
||||
(result-type (fourth processed-params))
|
||||
(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 session))
|
||||
(result (org-babel-ruby-evaluate session full-body result-type)))
|
||||
(result (org-babel-ruby-evaluate session full-body result-type)))
|
||||
(or (cdr (assoc :file params)) result)))
|
||||
|
||||
(defun org-babel-prep-session:ruby (session params)
|
||||
|
@ -61,7 +61,10 @@ In case you want to use a different screen than one selected by your $PATH")
|
||||
|
||||
(defun org-babel-prep-session:screen (session params)
|
||||
"Prepare SESSION according to the header arguments specified in PARAMS."
|
||||
(let* ((socket (org-babel-screen-session-socketname session))
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (first processed-params))
|
||||
(vars (second processed-params))
|
||||
(socket (org-babel-screen-session-socketname session))
|
||||
(vars (org-babel-ref-variables params))
|
||||
(cmd (cdr (assoc :cmd params)))
|
||||
(terminal (cdr (assoc :terminal params)))
|
||||
|
@ -40,14 +40,17 @@
|
||||
"Execute a block of Shell commands with org-babel. This
|
||||
function is called by `org-babel-execute-src-block' via multiple-value-bind."
|
||||
(message "executing Shell source code block")
|
||||
(let* ((full-body (concat
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(session (org-babel-sh-initiate-session (first processed-params)))
|
||||
(vars (second processed-params))
|
||||
(result-type (fourth processed-params))
|
||||
(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 session)))
|
||||
vars "\n") "\n" body "\n\n"))) ;; then the source block body
|
||||
(org-babel-sh-evaluate session full-body result-type)))
|
||||
|
||||
(defun org-babel-prep-session:sh (session params)
|
||||
|
Loading…
Reference in New Issue
Block a user