Re: [PATCH] Re: Export to attach directory?

2020-09-06 Thread Eric Abrahamsen
Nicolas Goaziou  writes:

> Hello,
>
> Eric Abrahamsen  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



Re: [PATCH] Re: Export to attach directory?

2020-09-06 Thread Nicolas Goaziou
Hello,

Eric Abrahamsen  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



Re: [PATCH] Re: Export to attach directory?

2020-09-06 Thread Eric Abrahamsen
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  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: 

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

>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



Re: [PATCH] Re: Export to attach directory?

2020-09-05 Thread Bastien
flare  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



Re: [PATCH] Re: Export to attach directory?

2020-09-05 Thread flare


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  writes:
>
>> Would something along these lines be considered for inclusion?
>
> Yes, sure, for after 9.4 -- please go ahead with a proper patch.
>
> Thanks,




Re: [PATCH] Re: Export to attach directory?

2020-09-05 Thread Bastien
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  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



[PATCH] Re: Export to attach directory?

2020-06-12 Thread Eric Abrahamsen
Eric Abrahamsen  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


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


Export to attach directory?

2020-06-02 Thread Eric Abrahamsen
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