org-exp: Handle recursively included setup files correctly.
authorBastien Guerry <bzg@altern.org>
Mon, 25 Jul 2011 13:32:52 +0000 (15:32 +0200)
committerBastien Guerry <bzg@altern.org>
Mon, 25 Jul 2011 13:44:22 +0000 (15:44 +0200)
* org-exp.el (org-infile-export-plist): Handle recursively
included setup files.  The value of the last included file
always takes precedence over previous values.

Thanks to Stefan Vollmar for signaling this bug.

lisp/org-exp.el

index 3e7e54b..f5dba50 100644 (file)
@@ -746,7 +746,7 @@ modified) list.")
            (case-fold-search t)
            p key val text options mathjax a pr style
            latex-header latex-class macros letbind
-           ext-setup-or-nil setup-contents (start 0))
+           ext-setup-or-nil setup-file setup-dir setup-contents (start 0))
        (while (or (and ext-setup-or-nil
                        (string-match re ext-setup-or-nil start)
                        (setq start (match-end 0)))
@@ -793,11 +793,14 @@ modified) list.")
           ((string-equal key "MACRO")
            (push val macros))
           ((equal key "SETUPFILE")
-           (setq setup-contents (org-file-contents
-                                 (expand-file-name
-                                  (org-remove-double-quotes
-                                   (org-trim val)))
-                                 'noerror))
+           (setq setup-file (org-remove-double-quotes (org-trim val))
+                 ;; take care of recursive inclusion of setupfiles
+                 setup-file (if (or (file-name-absolute-p val) (not setup-dir))
+                                (expand-file-name setup-file)
+                              (let ((default-directory setup-dir))
+                                (expand-file-name setup-file))))
+           (setq setup-dir (file-name-directory setup-file))
+           (setq setup-contents (org-file-contents setup-file 'noerror))
            (if (not ext-setup-or-nil)
                (setq ext-setup-or-nil setup-contents start 0)
              (setq ext-setup-or-nil