Browse Source

ob-exp: resolving code block parameters in the original file on export

* lisp/ob-exp.el (org-babel-exp-src-blocks): now switching back to the
  original file before resolving code block parameters to ensure
  headline and buffer wide parameters are taken into consideration
  when only a narrowed portion of the file is exported
Eric Schulte 14 years ago
parent
commit
efdf78172d
1 changed files with 31 additions and 4 deletions
  1. 31 4
      lisp/ob-exp.el

+ 31 - 4
lisp/ob-exp.el

@@ -95,14 +95,41 @@ none ----- do not display either code or results upon export"
   (message "org-babel-exp processing...")
   (save-excursion
     (goto-char (match-beginning 0))
-    (let* ((info (org-babel-get-src-block-info))
-	   (params (nth 2 info)))
+    (let* ((raw-header (match-string 3))
+	   (info (org-babel-get-src-block-info))
+	   (lang (nth 0 info))
+	   (lang-headers
+	    (intern (concat "org-babel-default-header-args:" lang)))
+	   (raw-params
+	    (org-babel-parse-header-arguments
+	     (org-babel-clean-text-properties
+	      (mapconcat #'identity (cdr (split-string raw-header)) " "))))
+	   (link (org-make-link-string
+		  (concat
+		   org-current-export-file
+		   "::"
+		   (nth 4 (ignore-errors (org-heading-components))))))
+	   (export-buffer (current-buffer)))
       ;; bail if we couldn't get any info from the block
       (when info
+	;; resolve parameters in the original file so that headline
+	;; and file-wide parameters are included
+	;; attempt to go to the same heading in the original file
+	(set-buffer (get-file-buffer org-current-export-file))
+	(save-restriction
+	  (org-open-link-from-string link)
+	  (setf (nth 2 info)
+		(org-babel-merge-params
+		 org-babel-default-header-args
+		 (org-babel-params-from-buffer)
+		 (org-babel-params-from-properties lang)
+		 (if (boundp lang-headers) (eval lang-headers) nil)
+		 raw-params)))
+	(set-buffer export-buffer)
 	;; expand noweb references in the original file
 	(setf (nth 1 info)
-	      (if (and (cdr (assoc :noweb params))
-		       (string= "yes" (cdr (assoc :noweb params))))
+	      (if (and (cdr (assoc :noweb (nth 2 info)))
+		       (string= "yes" (cdr (assoc :noweb (nth 2 info)))))
 		  (org-babel-expand-noweb-references
 		   info (get-file-buffer org-current-export-file))
 		(nth 1 info))))