* Export to attach directory? @ 2020-06-02 17:43 Eric Abrahamsen 2020-06-12 19:18 ` [PATCH] " Eric Abrahamsen 0 siblings, 1 reply; 8+ messages in thread From: Eric Abrahamsen @ 2020-06-02 17:43 UTC (permalink / raw) To: emacs-orgmode 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: Or maybe a property with an ATTACH prefix, I'm not sure. I find myself having to use Google Docs more and more, for collaboration, and this would let me use a package that mounts G-Docs on your filesystem, and export directly there. (And it would keep my Org directory tidy!) Has anyone cooked this up before? I wasn't able to find anything on the web. I'm imagining that org-attach.el could add something to `org-export-before-processing-hook', to check for the presence of this property, and set/rewrite the EXPORT_FILE_NAME property, if it's present. WDYT? Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] Re: Export to attach directory? 2020-06-02 17:43 Export to attach directory? Eric Abrahamsen @ 2020-06-12 19:18 ` Eric Abrahamsen 2020-09-05 7:44 ` Bastien 0 siblings, 1 reply; 8+ messages in thread From: Eric Abrahamsen @ 2020-06-12 19:18 UTC (permalink / raw) To: emacs-orgmode [-- 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 2020-06-12 19:18 ` [PATCH] " Eric Abrahamsen @ 2020-09-05 7:44 ` Bastien 2020-09-05 7:47 ` flare 2020-09-06 17:44 ` Eric Abrahamsen 0 siblings, 2 replies; 8+ messages in thread From: Bastien @ 2020-09-05 7:44 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: emacs-orgmode 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. Thanks, -- Bastien ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 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 1 sibling, 1 reply; 8+ messages in thread From: flare @ 2020-09-05 7:47 UTC (permalink / raw) To: emacs-orgmode While on the topic of attachments, a low priority goal which may be nice is to have a org-attach method that allows for automatic encryption of attachments. But again, not very important Bastien 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. > > Thanks, ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 2020-09-05 7:47 ` flare @ 2020-09-05 8:08 ` Bastien 0 siblings, 0 replies; 8+ messages in thread From: Bastien @ 2020-09-05 8:08 UTC (permalink / raw) To: flare; +Cc: emacs-orgmode flare <gabrielxaviersmith@gmail.com> writes: > While on the topic of attachments, a low priority goal which may be nice > is to have a org-attach method that allows for automatic encryption of > attachments. But again, not very important Patch welcome! -- Bastien ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 2020-09-05 7:44 ` Bastien 2020-09-05 7:47 ` flare @ 2020-09-06 17:44 ` Eric Abrahamsen 2020-09-06 22:03 ` Nicolas Goaziou 1 sibling, 1 reply; 8+ messages in thread From: Eric Abrahamsen @ 2020-09-06 17:44 UTC (permalink / raw) To: Bastien; +Cc: emacs-orgmode [-- 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 2020-09-06 17:44 ` Eric Abrahamsen @ 2020-09-06 22:03 ` Nicolas Goaziou 2020-09-06 23:53 ` Eric Abrahamsen 0 siblings, 1 reply; 8+ messages in thread From: Nicolas Goaziou @ 2020-09-06 22:03 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Bastien, emacs-orgmode Hello, Eric Abrahamsen <eric@ericabrahamsen.net> writes: > 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. Doesn't it conflict with publishing, and with EXPORT_FILE_NAME property/keyword? In both, you can already specify an output directory. > + (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)))))))))) See `org-collect-keywords'. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Re: Export to attach directory? 2020-09-06 22:03 ` Nicolas Goaziou @ 2020-09-06 23:53 ` Eric Abrahamsen 0 siblings, 0 replies; 8+ messages in thread From: Eric Abrahamsen @ 2020-09-06 23:53 UTC (permalink / raw) To: Bastien; +Cc: emacs-orgmode Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > Eric Abrahamsen <eric@ericabrahamsen.net> writes: > >> 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. > > Doesn't it conflict with publishing, and with EXPORT_FILE_NAME > property/keyword? In both, you can already specify an output directory. I did look at making this work with the publishing framework. The problem is that ox-publish looks like it will only do one or more files, whereas I'm trying to publish a subtree. More particularly, if there were a way to pass the PUB-DIR argument to `org-export-output-file-name', that would take care of it. But I can only export a subtree via the export dispatcher, and the export dispatcher only calls `org-*-export-to-*' functions, and all of those functions contain their own call to `org-export-output-file-name', so there's no clean way to inject PUB-DIR anywhere. You can't really wait until `org-export-as' does its general keyword gathering, either, since EXPORT_FILE_NAME and EXPORT_DIRECTORY both need to be available to `org-export-to-file'. So finding EXPORT_DIRECTORY in `org-export-output-file-name' seemed like the only option. I was imagining that EXPORT_FILE_NAME would take precedence, if it was an absolute filepath. Otherwise, the two options could be complementary. >> + (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)))))))))) > > See `org-collect-keywords'. I don't have this function! org-version -> "9.3.7" Thanks, Eric ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-09-06 23:54 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2020-09-06 22:03 ` Nicolas Goaziou 2020-09-06 23:53 ` Eric Abrahamsen
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).