emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Re: Export to attach directory?
Date: Fri, 12 Jun 2020 12:18:07 -0700	[thread overview]
Message-ID: <87a718m6ts.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87o8q18isr.fsf@ericabrahamsen.net

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

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> I think the last thing I'm missing before my Org set up is Absolutely
> Perfect and never needs to be tweaked again (ha!) is the ability to
> export Org files/subtrees to their relevant ATTACH directories, if any.
> It might be overkill to have a global setting for this, but I would
> love to be able to say:
>
> * Report #25                                                 :ATTACH:
> :PROPERTIES:
> :ID:       3da327aa-b51e-444a-ae5c-95bb56d025a9
> :EXPORT_FILE_NAME: report_25
> :EXPORT_TO_ATTACH: t
> :END:

Nobody seems super excited about this but...

I went poking to see how difficult it would be to do this only using
hooks and whatnot. It seemed a bit awkward: I can munge the export file
name altogether, but there's no good way to say "use whatever file name
you would have come up with, but put the resulting file in such-and-such
directory".

Mostly it's not possible to sneak in and add/alter the PUB-DIR argument
to `org-export-output-file-name' -- that argument only seems to be used
in the publishing framework.

The attached patch to `org-export-output-file-name' has it also check
for a EXPORT_PUB_DIR property at the heading level or document level;
that would allow libraries like org-attach.el a way to get at exporting
via a hook. (Maybe EXPORT_DIRECTORY would be a better name.)

Would something along these lines be considered for inclusion?

Thanks,
Eric



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: export-pub-dir-option.diff --]
[-- Type: text/x-patch, Size: 912 bytes --]

diff --git a/lisp/ox.el b/lisp/ox.el
index 9cf62078a..77cafb20d 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -6417,6 +6417,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_PUB_DIR" 'selective))
+		      (org-with-point-at (point-min)
+			(catch :found
+			  (let ((case-fold-search t))
+			    (while (re-search-forward
+				    "^[ \t]*#\\+EXPORT_PUB_DIR:[ \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

  reply	other threads:[~2020-06-12 19:18 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 ` Eric Abrahamsen [this message]
2020-09-05  7:44   ` [PATCH] " Bastien
2020-09-05  7:47     ` flare
2020-09-05  8:08       ` Bastien
2020-09-06 17:44     ` Eric Abrahamsen
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=87a718m6ts.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --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).