Quellcode durchsuchen

org-babel: nested calls inherit header args from enclosing scopes

And when merging header args, those from enclosing scopes take
precedence. For example, output to file from a source block is
implemented by (a) sending the output to file, and (b) having the
source block return the file name as its result. Before this change,
the file name returned could be set by a referenced source block (a
nested call), regardless of the value of the :file header arg of the
top-level source block.
Dan Davison vor 15 Jahren
Ursprung
Commit
0d10946cff
1 geänderte Dateien mit 15 neuen und 13 gelöschten Zeilen
  1. 15 13
      contrib/babel/lisp/org-babel-ref.el

+ 15 - 13
contrib/babel/lisp/org-babel-ref.el

@@ -57,10 +57,12 @@
 (defun org-babel-ref-variables (params)
 (defun org-babel-ref-variables (params)
   "Takes a parameter alist, and return an alist of variable
   "Takes a parameter alist, and return an alist of variable
 names, and the emacs-lisp representation of the related value."
 names, and the emacs-lisp representation of the related value."
-  (mapcar #'org-babel-ref-parse
-          (delq nil (mapcar (lambda (pair) (if (eq (car pair) :var) (cdr pair))) params))))
+  (let ((assignments
+	 (delq nil (mapcar (lambda (pair) (if (eq (car pair) :var) (cdr pair))) params)))
+	(other-params (assq-delete-all :var params)))
+    (mapcar (lambda (assignment) (org-babel-ref-parse assignment other-params)) assignments)))
 
 
-(defun org-babel-ref-parse (assignment)
+(defun org-babel-ref-parse (assignment params)
   "Parse a variable ASSIGNMENT in a header argument.  If the
   "Parse a variable ASSIGNMENT in a header argument.  If the
 right hand side of the assignment has a literal value return that
 right hand side of the assignment has a literal value return that
 value, otherwise interpret as a reference to an external resource
 value, otherwise interpret as a reference to an external resource
@@ -74,7 +76,7 @@ emacs-lisp representation of the value of the variable."
             (ref (match-string 2 assignment)))
             (ref (match-string 2 assignment)))
         (cons (intern var)
         (cons (intern var)
               (or (org-babel-ref-literal ref)
               (or (org-babel-ref-literal ref)
-                  (org-babel-ref-resolve-reference ref))))))
+                  (org-babel-ref-resolve-reference ref params))))))
 
 
 (defun org-babel-ref-literal (ref)
 (defun org-babel-ref-literal (ref)
   "Determine if the right side of a header argument variable
   "Determine if the right side of a header argument variable
@@ -87,7 +89,7 @@ return nil."
             (read ref))
             (read ref))
       out)))
       out)))
 
 
-(defun org-babel-ref-resolve-reference (ref)
+(defun org-babel-ref-resolve-reference (ref params)
   "Resolve the reference and return its value"
   "Resolve the reference and return its value"
   (save-excursion
   (save-excursion
     (let ((case-fold-search t)
     (let ((case-fold-search t)
@@ -134,14 +136,14 @@ return nil."
           (beginning-of-line)
           (beginning-of-line)
           (if (or (= (point) (point-min)) (= (point) (point-max)))
           (if (or (= (point) (point-min)) (= (point) (point-max)))
               (error "reference not found"))))
               (error "reference not found"))))
-      ;; (message "type=%S" type) ;; debugging
-      (case type
-        ('results-line (org-babel-read-result))
-        ('table (org-babel-read-table))
-        ('source-block
-         (setq result (org-babel-execute-src-block t nil args))
-         (if (symbolp result) (format "%S" result) result))
-        ('lob (setq result (org-babel-execute-src-block t lob-info args)))))))
+      (setq params (org-babel-merge-params params args))
+      (setq result
+	    (case type
+	      ('results-line (org-babel-read-result))
+	      ('table (org-babel-read-table))
+	      ('source-block (org-babel-execute-src-block t nil params))
+	      ('lob (org-babel-execute-src-block t lob-info params))))
+      (if (symbolp result) (format "%S" result) result))))
 
 
 (defun org-babel-ref-split-args (arg-string)
 (defun org-babel-ref-split-args (arg-string)
   "Split ARG-STRING into top-level arguments of balanced parenthesis."
   "Split ARG-STRING into top-level arguments of balanced parenthesis."