emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Re: Export to attach directory?
Date: Sun, 06 Sep 2020 10:44:33 -0700	[thread overview]
Message-ID: <877dt6u7em.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87363w8y7g.fsf@gnu.org> (Bastien's message of "Sat, 05 Sep 2020 09:44:19 +0200")

[-- Attachment #1: Type: text/plain, Size: 1136 bytes --]

Bastien <bzg@gnu.org> writes:

> Hi Eric,
>
> sorry for the late reply -- I don't use attachments that much
> but I see how this could be useful once correctly advertized and
> documented.
>
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Would something along these lines be considered for inclusion?
>
> Yes, sure, for after 9.4 -- please go ahead with a proper patch.

How does this look? It occurred to me that having a global
`org-export-directory' option would be a good thing -- it makes sense to
me that a user might want all their exported files put in one place --
but in the interest of one-thing-at-a-time I didn't do that.

This additional property doesn't actually have anything to do with
org-attach. I'd originally thought that, with this option, I could write
an export filter that would check for:

:EXPORT_DIRECTORY: <ATTACH_DIR>

and replace it to point at whatever the attach dir was/should be for
that heading.

If that's something that many users would like to have, we could look at
adding it in org-attach.el. But in the meantime, the attached patch
makes it possible to do it yourself.

Thanks,
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-EXPORT_DIRECTORY-property.patch --]
[-- Type: text/x-patch, Size: 2319 bytes --]

From 0e80a6ed7ad955259c4e11ea74ed249696ba9b46 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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


  parent reply	other threads:[~2020-09-06 17:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-02 17:43 Export to attach directory? Eric Abrahamsen
2020-06-12 19:18 ` [PATCH] " Eric Abrahamsen
2020-09-05  7:44   ` Bastien
2020-09-05  7:47     ` flare
2020-09-05  8:08       ` Bastien
2020-09-06 17:44     ` Eric Abrahamsen [this message]
2020-09-06 22:03       ` Nicolas Goaziou
2020-09-06 23:53         ` Eric Abrahamsen

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=877dt6u7em.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /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).