emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 2/2] fix SETUPFILE pathname expansion from within an INCLUDE


From: Richard Hansen
Subject: [O] [PATCH 2/2] fix SETUPFILE pathname expansion from within an INCLUDE
Date: Thu, 24 Sep 2015 18:20:41 -0400

* lisp/ox.el (defun org-export-expand-include-keyword):  cd instead of
passing DIR to expand-file-name so that if the INCLUDE file has a
SETUPFILE line with a relative pathname the full pathname to the
SETUPFILE will be expanded properly.

Assume the following files:

  /home/foo/a.org:
    #+INCLUDE: subdir/b.org

  /home/foo/subdir/b.org:
    #+SETUPFILE: c.org

  /home/foo/subdir/c.org:
    stuff

Before, if /home/foo/a.org was opened and exported, org-mode would try
(and fail) to read /home/foo/c.org.  With this change, org-mode reads
/home/foo/subdir/c.org as expected.

!!! TEST CASE NEEDED !!!

TINYCHANGE
---
 lisp/ox.el | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 0adbdf2..186a378 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3149,14 +3149,13 @@ locally for the subtree through node properties."
                   (car key)
                   (if (org-string-nw-p val) (format " %s" val) ""))))))))
 
-(defun org-export-expand-include-keyword (&optional included dir footnotes)
+(defun org-export-expand-include-keyword (&optional included footnotes)
   "Expand every include keyword in buffer.
 Optional argument INCLUDED is a list of included file names along
 with their line restriction, when appropriate.  It is used to
-avoid infinite recursion.  Optional argument DIR is the current
-working directory.  It is used to properly resolve relative
-paths.  Optional argument FOOTNOTES is a hash-table used for
-storing and resolving footnotes.  It is created automatically."
+avoid infinite recursion.  Optional argument FOOTNOTES is a
+hash-table used for storing and resolving footnotes.  It is
+created automatically."
   (let ((case-fold-search t)
        (file-prefix (make-hash-table :test #'equal))
        (current-prefix 0)
@@ -3194,8 +3193,7 @@ storing and resolving footnotes.  It is created 
automatically."
                                       (replace-match "" nil nil matched 1)))
                               (expand-file-name
                                (org-remove-double-quotes
-                                matched)
-                               dir)))
+                                matched))))
                         (setq value (replace-match "" nil nil value)))))
                 (only-contents
                  (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
@@ -3261,6 +3259,8 @@ storing and resolving footnotes.  It is created 
automatically."
               (t
                (insert
                 (with-temp-buffer
+                  (setq default-directory
+                        (file-name-directory file))
                   (let ((org-inhibit-startup t)
                         (lines
                          (if location
@@ -3276,7 +3276,6 @@ storing and resolving footnotes.  It is created 
automatically."
                       footnotes)))
                   (org-export-expand-include-keyword
                    (cons (list file lines) included)
-                   (file-name-directory file)
                    footnotes)
                   (buffer-string)))))
              ;; Expand footnotes after all files have been included.
-- 
2.5.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]