summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-10-16 12:14:20 -0600
committerDan Davison <davison@stats.ox.ac.uk>2010-10-21 13:06:01 +0100
commit43c712fccb775031ddce84b50d2dea45dc258d8f (patch)
tree950f753c45fbf35be8235e94f868f80dabfd84d7
parentfd97cb938696dce0f8abfa54ada098e5a43448ea (diff)
downloadorg-mode-43c712fccb775031ddce84b50d2dea45dc258d8f.tar.gz
unifying ob-process-params and ob-expand-variables
* lisp/ob-exp.el (org-babel-exp-results): replaced old function call * lisp/ob-lob.el (org-babel-lob-execute): replaced old function call * lisp/ob-ref.el (org-babel-ref-parse): removed obsolete optional params argument, also no longer chokes when handed an already-resolved reference (org-babel-ref-resolve): removed obsolete optional params argument * lisp/ob.el (org-babel-ref-parse): updated function declaration (org-babel-get-src-block-info): replaced old function call (org-babel-header-arg-names): indentation (org-babel-execute-src-block): now expanding all parameters using the newly combined org-babel-process-params (org-babel-switch-to-session-with-code): indentation (org-mode-hook): indentation (org-babel-process-params): now packages all results into the parameter alist and does variable expansion, this should no longer be called from inside of language functions (org-babel-expand-noweb-references): updated function call for newly removed obsolete function parameter
-rw-r--r--lisp/ob-exp.el2
-rw-r--r--lisp/ob-lob.el2
-rw-r--r--lisp/ob-ref.el31
-rw-r--r--lisp/ob.el96
4 files changed, 63 insertions, 68 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index a377058..e7269ef 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -286,7 +286,7 @@ inhibit insertion of results into the buffer."
(let ((lang (nth 0 info))
(body (nth 1 info)))
(setf (nth 2 info) (org-babel-exp-in-export-file
- (org-babel-expand-variables (nth 2 info))))
+ (org-babel-process-params (nth 2 info))))
;; skip code blocks which we can't evaluate
(when (fboundp (intern (concat "org-babel-execute:" lang)))
(if (equal type 'inline)
diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el
index 034c69f..3560a18 100644
--- a/lisp/ob-lob.el
+++ b/lisp/ob-lob.el
@@ -101,7 +101,7 @@ if so then run the appropriate source block from the Library."
(defun org-babel-lob-execute (info)
"Execute the lob call specified by INFO."
- (let ((params (org-babel-expand-variables
+ (let ((params (org-babel-process-params
(org-babel-merge-params
org-babel-default-header-args
(org-babel-params-from-buffer)
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index 87195a5..bcb1515 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -60,23 +60,23 @@
(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]*")
-(defun org-babel-ref-parse (assignment &optional params)
+(defun org-babel-ref-parse (assignment)
"Parse a variable ASSIGNMENT in a header argument.
If the right hand side of the assignment has a literal value
return that value, otherwise interpret as a reference to an
external resource and find it's value using
-`org-babel-ref-resolve-reference'. Return a list with two
-elements. The first element of the list will be the name of the
-variable, and the second will be an emacs-lisp representation of
-the value of the variable."
- (if (string-match org-babel-ref-split-regexp assignment)
- (let ((var (match-string 1 assignment))
- (ref (match-string 2 assignment)))
- (cons (intern var)
- ((lambda (val)
- (if (equal :ob-must-be-reference val)
- (org-babel-ref-resolve-reference ref params)
- val)) (org-babel-ref-literal ref))))))
+`org-babel-ref-resolve'. Return a list with two elements. The
+first element of the list will be the name of the variable, and
+the second will be an emacs-lisp representation of the value of
+the variable."
+ (when (string-match org-babel-ref-split-regexp assignment)
+ (let ((var (match-string 1 assignment))
+ (ref (match-string 2 assignment)))
+ (cons (intern var)
+ ((lambda (val)
+ (if (equal :ob-must-be-reference val)
+ (org-babel-ref-resolve ref) val))
+ (org-babel-ref-literal ref))))))
(defun org-babel-ref-literal (ref)
"Return the value of REF if it is a literal value.
@@ -93,7 +93,7 @@ return nil."
out)))
(defvar org-babel-library-of-babel)
-(defun org-babel-ref-resolve-reference (ref &optional params)
+(defun org-babel-ref-resolve (ref)
"Resolve the reference REF and return its value."
(save-excursion
(let ((case-fold-search t)
@@ -149,8 +149,7 @@ return nil."
(beginning-of-line)
(if (or (= (point) (point-min)) (= (point) (point-max)))
(error "reference not found"))))
- (setq params (org-babel-merge-params
- params (org-babel-expand-variables args) '((:results . "silent"))))
+ (setq params (org-babel-process-params '((:results . "silent"))))
(setq result
(case type
('results-line (org-babel-read-result))
diff --git a/lisp/ob.el b/lisp/ob.el
index b52f678..a8d0599 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -68,7 +68,7 @@
(declare-function orgtbl-to-orgtbl "org-table" (table params))
(declare-function org-babel-lob-get-info "ob-lob" nil)
(declare-function org-babel-ref-split-args "ob-ref" (arg-string))
-(declare-function org-babel-ref-parse "ob-ref" (assignment &optional params))
+(declare-function org-babel-ref-parse "ob-ref" (assignment))
(declare-function org-babel-lob-execute-maybe "ob-lob" ())
(declare-function org-number-sequence "org-compat" (from &optional to inc))
@@ -152,12 +152,6 @@ not match KEY should be returned."
(lambda (p) (when (funcall (if others #'not #'identity) (eq (car p) key)) p))
params)))
-(defun org-babel-expand-variables (params)
- "Expand variables in PARAMS."
- (append (mapcar (lambda (el) (cons :var (org-babel-ref-parse (cdr el))))
- (org-babel-get-header params :var))
- (org-babel-get-header params :var 'other)))
-
(defun org-babel-get-src-block-info (&optional light)
"Get information on the current source block.
@@ -193,9 +187,9 @@ Returns a list
(when (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t)
(looking-at org-babel-inline-src-block-regexp))
(setq info (org-babel-parse-inline-src-block-match))))
- ;; resolve variable references
+ ;; resolve variable references and add summary parameters
(when (and info (not light))
- (setf (nth 2 info) (org-babel-expand-variables (nth 2 info))))
+ (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
(when info (append info (list name indent)))))
(defun org-babel-confirm-evaluate (info)
@@ -281,7 +275,7 @@ then run `org-babel-pop-to-session'."
(defconst org-babel-header-arg-names
'(cache cmdline colnames dir exports file noweb results
- session tangle var eval noeval comments)
+ session tangle var eval noeval comments)
"Common header arguments used by org-babel.
Note that individual languages may define their own language
specific header arguments as well.")
@@ -357,7 +351,10 @@ block."
(let ((info (or info (org-babel-get-src-block-info))))
(when (org-babel-confirm-evaluate info)
(let* ((lang (nth 0 info))
- (params (org-babel-merge-params (nth 2 info) params))
+ (params (if params
+ (org-babel-process-params
+ (org-babel-merge-params (nth 2 info) params))
+ (nth 2 info)))
(cache? (and (cdr (assoc :cache params))
(string= "yes" (cdr (assoc :cache params)))))
(params (setf (nth 2 info)
@@ -374,10 +371,6 @@ block."
(string= "yes" (cdr (assoc :noweb params))))
(org-babel-expand-noweb-references info)
(nth 1 info))))
- (result-params (split-string (or (cdr (assoc :results params)) "")))
- (result-type (cond ((member "output" result-params) 'output)
- ((member "value" result-params) 'value)
- (t 'value)))
(cmd (intern (concat "org-babel-execute:" lang)))
(dir (cdr (assoc :dir params)))
(default-directory
@@ -390,7 +383,7 @@ block."
result)
(unwind-protect
(flet ((call-process-region (&rest args)
- (apply 'org-babel-tramp-handle-call-process-region args)))
+ (apply 'org-babel-tramp-handle-call-process-region args)))
(unless (fboundp cmd)
(error "No org-babel-execute function for %s!" lang))
(if (and (not arg) new-hash (equal new-hash old-hash))
@@ -513,20 +506,20 @@ with a prefix argument then this is passed on to
;;;###autoload
(defun org-babel-switch-to-session-with-code (&optional arg info)
- "Switch to code buffer and display session."
- (interactive "P")
- (flet ((swap-windows
- ()
- (let ((other-window-buffer (window-buffer (next-window))))
- (set-window-buffer (next-window) (current-buffer))
- (set-window-buffer (selected-window) other-window-buffer))
- (other-window 1)))
- (let ((info (org-babel-get-src-block-info))
- (org-src-window-setup 'reorganize-frame))
- (save-excursion
- (org-babel-switch-to-session arg info))
- (org-edit-src-code))
- (swap-windows)))
+ "Switch to code buffer and display session."
+ (interactive "P")
+ (flet ((swap-windows
+ ()
+ (let ((other-window-buffer (window-buffer (next-window))))
+ (set-window-buffer (next-window) (current-buffer))
+ (set-window-buffer (selected-window) other-window-buffer))
+ (other-window 1)))
+ (let ((info (org-babel-get-src-block-info))
+ (org-src-window-setup 'reorganize-frame))
+ (save-excursion
+ (org-babel-switch-to-session arg info))
+ (org-edit-src-code))
+ (swap-windows)))
(defmacro org-babel-do-in-edit-buffer (&rest body)
"Evaluate BODY in edit buffer if there is a code block at point.
@@ -750,7 +743,7 @@ portions of results lines."
;; Remove overlays when changing major mode
(add-hook 'org-mode-hook
(lambda () (org-add-hook 'change-major-mode-hook
- 'org-babel-show-result-all 'append 'local)))
+ 'org-babel-show-result-all 'append 'local)))
(defmacro org-babel-map-src-blocks (file &rest body)
"Evaluate BODY forms on each source-block in FILE.
@@ -902,23 +895,27 @@ may be specified at the top of the current buffer."
(split-string (concat " " arg-string) "[ \f\t\n\r\v]+:" t)))))
(defun org-babel-process-params (params)
- "Parse params and resolve references.
-
-Return a list (session vars result-params result-type colnames rownames)."
- (let* ((session (cdr (assoc :session params)))
- (vars-and-names (org-babel-disassemble-tables
- (mapcar #'cdr (org-babel-get-header params :var))
- (cdr (assoc :hlines params))
- (cdr (assoc :colnames params))
- (cdr (assoc :rownames params))))
- (vars (car vars-and-names))
- (colnames (cadr vars-and-names))
- (rownames (caddr vars-and-names))
- (result-params (split-string (or (cdr (assoc :results params)) "")))
- (result-type (cond ((member "output" result-params) 'output)
- ((member "value" result-params) 'value)
- (t 'value))))
- (list session vars result-params result-type colnames rownames)))
+ "Expand variables in PARAMS and add summary parameters."
+ (let ((vars-and-names (org-babel-disassemble-tables
+ (mapcar
+ (lambda (el) (cons :var (if (consp (cdr el))
+ (cdr el)
+ (org-babel-ref-parse (cdr el)))))
+ (org-babel-get-header params :var))
+ (cdr (assoc :hlines params))
+ (cdr (assoc :colnames params))
+ (cdr (assoc :rownames params))))
+ (result-params (split-string (or (cdr (assoc :results params)) ""))))
+ (append
+ (car vars-and-names)
+ (list
+ (cons :colname-names (cadr vars-and-names))
+ (cons :rowname-names (caddr vars-and-names))
+ (cons :result-params result-params)
+ (cons :results-type (cond ((member "output" result-params) 'output)
+ ((member "value" result-params) 'value)
+ (t 'value))))
+ (org-babel-get-header params :var 'other))))
;; row and column names
(defun org-babel-del-hlines (table)
@@ -1667,8 +1664,7 @@ block but are passed literally to the \"example-block\"."
#'identity
(split-string
(if evaluate
- (let ((raw (org-babel-ref-resolve-reference
- source-name nil)))
+ (let ((raw (org-babel-ref-resolve source-name)))
(if (stringp raw) raw (format "%S" raw)))
(save-restriction
(widen)