org-babel: cleaner passing of parameter to language specific files
This commit is contained in:
parent
3ebaffe07e
commit
082fb84c34
|
@ -59,8 +59,9 @@
|
||||||
names, and the emacs-lisp representation of the related value."
|
names, and the emacs-lisp representation of the related value."
|
||||||
(let ((assignments
|
(let ((assignments
|
||||||
(delq nil (mapcar (lambda (pair) (if (eq (car pair) :var) (cdr pair))) params)))
|
(delq nil (mapcar (lambda (pair) (if (eq (car pair) :var) (cdr pair))) params)))
|
||||||
(other-params (assq-delete-all :var params)))
|
(others
|
||||||
(mapcar (lambda (assignment) (org-babel-ref-parse assignment other-params)) assignments)))
|
(delq nil (mapcar (lambda (pair) (unless (eq :var (car pair)) pair)) params))))
|
||||||
|
(mapcar (lambda (assignment) (org-babel-ref-parse assignment others)) assignments)))
|
||||||
|
|
||||||
(defvar org-babel-ref-split-regexp
|
(defvar org-babel-ref-split-regexp
|
||||||
"[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*")
|
"[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*")
|
||||||
|
|
|
@ -61,12 +61,11 @@
|
||||||
string))
|
string))
|
||||||
|
|
||||||
(defmacro sbe (source-block &rest variables)
|
(defmacro sbe (source-block &rest variables)
|
||||||
"Return the results of calling SOURCE-BLOCK with all assigning
|
"Return the results of calling SOURCE-BLOCK assigning every
|
||||||
every variable in VARIABLES. Each element of VARIABLES should be
|
variable in VARIABLES. Each element of VARIABLES should be a two
|
||||||
a two element list, whose first element is the name of the
|
element list, whose first element is the name of the variable and
|
||||||
variable and second element is a string of its value. The
|
second element is a string of its value. The following call to
|
||||||
following call to `sbe' would be equivalent to the following
|
`sbe' would be equivalent to the following source code block.
|
||||||
source code block.
|
|
||||||
|
|
||||||
(sbe 'source-block (n 2) (m 3))
|
(sbe 'source-block (n 2) (m 3))
|
||||||
|
|
||||||
|
@ -85,7 +84,9 @@ results
|
||||||
(format "%S=%s" (first var-spec) (second var-spec)))
|
(format "%S=%s" (first var-spec) (second var-spec)))
|
||||||
',variables ", ")
|
',variables ", ")
|
||||||
")")))))
|
")")))))
|
||||||
(org-babel-execute-src-block t (list "emacs-lisp" "results" params)))
|
(org-babel-execute-src-block
|
||||||
|
nil (list "emacs-lisp" "results"
|
||||||
|
(org-babel-merge-params '((:results . "silent")) params))))
|
||||||
"")))
|
"")))
|
||||||
|
|
||||||
(provide 'org-babel-table)
|
(provide 'org-babel-table)
|
||||||
|
|
|
@ -189,15 +189,17 @@ the header arguments specified at the source code block."
|
||||||
(result-type (fourth processed-params))
|
(result-type (fourth processed-params))
|
||||||
(cmd (intern (concat "org-babel-execute:" lang)))
|
(cmd (intern (concat "org-babel-execute:" lang)))
|
||||||
result)
|
result)
|
||||||
;; (message "params=%S" params) ;; debugging statement
|
;; (message "params=%S" params) ;; debugging
|
||||||
;; (message "vars=%S" (second processed-params)) ;; debugging statement
|
|
||||||
(unless (member lang org-babel-interpreters)
|
(unless (member lang org-babel-interpreters)
|
||||||
(error "Language is not in `org-babel-interpreters': %s" lang))
|
(error "Language is not in `org-babel-interpreters': %s" lang))
|
||||||
(when arg (setq result-params (cons "silent" result-params)))
|
(when arg (setq result-params (cons "silent" result-params)))
|
||||||
(setq result (multiple-value-bind (session vars result-params result-type) processed-params
|
(setq result (funcall cmd body params))
|
||||||
(funcall cmd body params)))
|
|
||||||
(if (eq result-type 'value)
|
(if (eq result-type 'value)
|
||||||
(setq result (org-babel-process-value-result result result-params)))
|
(setq result (if (and (or (member "vector" result-params)
|
||||||
|
(member "table" result-params))
|
||||||
|
(not (listp result)))
|
||||||
|
(list (list result))
|
||||||
|
result)))
|
||||||
(org-babel-insert-result result result-params info)
|
(org-babel-insert-result result result-params info)
|
||||||
result))
|
result))
|
||||||
|
|
||||||
|
@ -267,26 +269,6 @@ results already exist."
|
||||||
(insert (echo-res results))))))
|
(insert (echo-res results))))))
|
||||||
t)))
|
t)))
|
||||||
|
|
||||||
(defun org-babel-process-value-result (result result-params)
|
|
||||||
"Process returned value for insertion in buffer.
|
|
||||||
|
|
||||||
Currently, this function forces to table output if :results
|
|
||||||
table or :results vector has been supplied.
|
|
||||||
|
|
||||||
You can see below the various fragments of results-processing
|
|
||||||
code that were present in the language-specific files. Out of
|
|
||||||
those fragments, I've moved the org-babel-python-table-or-results
|
|
||||||
and org-babel-import-elisp-from-file functionality into the
|
|
||||||
org-babel-*-evaluate functions. I think those should only be used
|
|
||||||
in the :results value case, as in the 'output case we are not
|
|
||||||
concerned with creating elisp versions of results. "
|
|
||||||
|
|
||||||
(if (and (or (member "vector" result-params)
|
|
||||||
(member "table" result-params))
|
|
||||||
(not (listp result)))
|
|
||||||
(list (list result))
|
|
||||||
result))
|
|
||||||
|
|
||||||
(defun org-babel-execute-buffer (&optional arg)
|
(defun org-babel-execute-buffer (&optional arg)
|
||||||
"Replace EVAL snippets in the entire buffer."
|
"Replace EVAL snippets in the entire buffer."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
|
|
Loading…
Reference in New Issue