From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Hansen Subject: [PATCH 2/2] fix SETUPFILE pathname expansion from within an INCLUDE Date: Thu, 24 Sep 2015 18:20:41 -0400 Message-ID: <1443133241-501-2-git-send-email-rhansen@bbn.com> References: <56047142.1060404@bbn.com> <1443133241-501-1-git-send-email-rhansen@bbn.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfEt1-0005Xh-Sr for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 18:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfEsy-000340-2g for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 18:21:07 -0400 Received: from smtp.bbn.com ([128.33.0.80]:53925) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfEsx-00033w-Vg for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 18:21:03 -0400 In-Reply-To: <1443133241-501-1-git-send-email-rhansen@bbn.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Richard Hansen * 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