From 0e80a6ed7ad955259c4e11ea74ed249696ba9b46 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 6 Sep 2020 10:36:34 -0700 Subject: [PATCH] Add EXPORT_DIRECTORY property * lisp/ox.el (org-export-output-file-name): Check for this property and place the exported output file there. * doc/org-manual.org: Document. --- doc/org-manual.org | 8 +++++++- lisp/ox.el | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 46498bd22..6f256a569 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -11479,7 +11479,7 @@ global variables, include: - =CREATOR= :: #+cindex: @samp{CREATOR}, keyword - #+vindex: org-expot-creator-string + #+vindex: org-export-creator-string Entity responsible for output generation (~org-export-creator-string~). @@ -11539,6 +11539,12 @@ global variables, include: generates the file name based on the buffer name and the extension based on the back-end format. +- =EXPORT_DIRECTORY= :: + + #+cindex: @samp{EXPORT_DIRECTORY}, keyword + An alternate directory in which to place the output file. + Otherwise, output files are placed alongside the original Org file. + The =OPTIONS= keyword is a compact form. To configure multiple options, use several =OPTIONS= lines. =OPTIONS= recognizes the following arguments. diff --git a/lisp/ox.el b/lisp/ox.el index 9852cfd21..2d2c1ddb0 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -6428,6 +6428,20 @@ Return file name as a string." "Output file: " pub-dir nil nil nil (lambda (n) (string= extension (file-name-extension n t)))))) extension)) + (pub-dir (or pub-dir + (and subtreep (org-entry-get + nil "EXPORT_DIRECTORY" 'selective)) + (org-with-point-at (point-min) + (catch :found + (let ((case-fold-search t)) + (while (re-search-forward + "^[ \t]*#\\+EXPORT_DIRECTORY:[ \t]+\\S-" + nil t) + (let ((element (org-element-at-point))) + (when (eq 'keyword (org-element-type element)) + (throw :found + (org-element-property + :value element)))))))))) (output-file ;; Build file name. Enforce EXTENSION over whatever user ;; may have come up with. PUB-DIR, if defined, always has -- 2.28.0