emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Hansen <rhansen@bbn.com>
To: kyle@kyleam.com, mail@nicolasgoaziou.fr, emacs-orgmode@gnu.org
Cc: Richard Hansen <rhansen@bbn.com>
Subject: [PATCH v3] fix SETUPFILE pathname expansion with subdirectories
Date: Sun, 20 Sep 2015 01:28:53 -0400	[thread overview]
Message-ID: <1442726933-14360-1-git-send-email-rhansen@bbn.com> (raw)
In-Reply-To: <87bncxhe5i.fsf@kyleam.com>

* lisp/org-macro.el (org-macro--collect-macros): cd to the directory
containing the SETUPFILE before recursing so that relative pathnames
in the SETUPFILE are expanded properly.

* lisp/org.el (org--setup-collect-keywords): cd to the directory
containing the SETUPFILE before recursing so that relative pathnames
in the SETUPFILE are expanded properly.

* lisp/ox.el (org-export--get-inbuffer-options,
org-export--list-bound-variables): cd to the directory containing the
SETUPFILE before recursing so that relative pathnames in the SETUPFILE
are expanded properly.

If /path/to/foo.org contains:

    #+SETUPFILE: settings/beamer.org

and /path/to/settings/beamer.org contains:

    #+SETUPFILE: common.org

then we want to read /path/to/settings/common.org, not
/path/to/common.org.

TINYCHANGE
---
Patch changelog:
  v3: use (setq default-directory ...) instead of (cd ...)
  v2: fix a couple more cases; add some tests

 lisp/org-macro.el                      | 2 ++
 lisp/org.el                            | 1 +
 lisp/ox.el                             | 4 ++++
 testing/examples/setupfile.org         | 7 +------
 testing/examples/setupfile3.org        | 6 ++++++
 testing/examples/subdir/setupfile2.org | 1 +
 6 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 testing/examples/setupfile3.org
 create mode 100644 testing/examples/subdir/setupfile2.org

diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index 65795f6..e808972 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -106,6 +106,8 @@ Return an alist containing all macro templates found."
 				      (org-remove-double-quotes val))))
 			   (unless (member file files)
 			     (with-temp-buffer
+			       (setq default-directory
+				     (file-name-directory file))
 			       (org-mode)
 			       (insert (org-file-contents file 'noerror))
 			       (setq templates
diff --git a/lisp/org.el b/lisp/org.el
index 74fe4ae..bd5a183 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5194,6 +5194,7 @@ Return value contains the following keys: `archive', `category',
 				(org-remove-double-quotes value)))))
 		   (when (and f (file-readable-p f) (not (member f files)))
 		     (with-temp-buffer
+		       (setq default-directory (file-name-directory f))
 		       (insert-file-contents f)
 		       (setq alist
 			     ;; Fake Org mode to benefit from cache
diff --git a/lisp/ox.el b/lisp/ox.el
index bfdfeba..477fc06 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1455,6 +1455,8 @@ Assume buffer is in Org mode.  Narrowing, if any, is ignored."
 			 ;; Avoid circular dependencies.
 			 (unless (member file files)
 			   (with-temp-buffer
+			     (setq default-directory
+				   (file-name-directory file))
 			     (insert (org-file-contents file 'noerror))
 			     (let ((org-inhibit-startup t)) (org-mode))
 			     (setq plist (funcall get-options
@@ -1586,6 +1588,8 @@ an alist where associations are (VARIABLE-NAME VALUE)."
 					(org-remove-double-quotes val))))
 			     (unless (member file files)
 			       (with-temp-buffer
+				 (setq default-directory
+				       (file-name-directory file))
 				 (let ((org-inhibit-startup t)) (org-mode))
 				 (insert (org-file-contents file 'noerror))
 				 (setq alist
diff --git a/testing/examples/setupfile.org b/testing/examples/setupfile.org
index a85dbc0..71acfca 100644
--- a/testing/examples/setupfile.org
+++ b/testing/examples/setupfile.org
@@ -1,6 +1 @@
-#+BIND: variable value
-#+DESCRIPTION: l2
-#+LANGUAGE: en
-#+SELECT_TAGS: b
-#+TITLE: b
-#+PROPERTY: a 1
+#+SETUPFILE: subdir/setupfile2.org
diff --git a/testing/examples/setupfile3.org b/testing/examples/setupfile3.org
new file mode 100644
index 0000000..a85dbc0
--- /dev/null
+++ b/testing/examples/setupfile3.org
@@ -0,0 +1,6 @@
+#+BIND: variable value
+#+DESCRIPTION: l2
+#+LANGUAGE: en
+#+SELECT_TAGS: b
+#+TITLE: b
+#+PROPERTY: a 1
diff --git a/testing/examples/subdir/setupfile2.org b/testing/examples/subdir/setupfile2.org
new file mode 100644
index 0000000..31586fa
--- /dev/null
+++ b/testing/examples/subdir/setupfile2.org
@@ -0,0 +1 @@
+#+SETUPFILE: ../setupfile3.org
-- 
2.5.3

  reply	other threads:[~2015-09-20  5:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19  0:22 [PATCH] fix SETUPFILE pathname expansion with subdirectories Richard Hansen
2015-09-19  8:16 ` Nicolas Goaziou
2015-09-19 20:18   ` Richard Hansen
2015-09-19 22:07   ` [PATCH v2] " Richard Hansen
2015-09-19 22:43     ` Kyle Meyer
2015-09-19 23:14       ` Richard Hansen
2015-09-20  5:07         ` Kyle Meyer
2015-09-20  5:28           ` Richard Hansen [this message]
2015-09-22 22:28             ` [PATCH v3] " Richard Hansen
2015-09-24  8:22               ` Nicolas Goaziou
2015-09-24 21:55                 ` Richard Hansen
2015-09-24 22:20                   ` [PATCH 1/2] test INCLUDE " Richard Hansen
2015-09-24 22:20                     ` [PATCH 2/2] fix SETUPFILE pathname expansion from within an INCLUDE Richard Hansen
2015-09-25 11:58                       ` Nicolas Goaziou
2015-09-25 11:51                   ` [PATCH v3] fix SETUPFILE pathname expansion with subdirectories Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442726933-14360-1-git-send-email-rhansen@bbn.com \
    --to=rhansen@bbn.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=kyle@kyleam.com \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).