Re: [BUG] EXPORT_FILE_NAME keyword is used by `org-export-output-file-name' before macro expansion/INCLUDEs/removing COMMENTed trees (was: Confused about what the COMMENT keyword means)

2022-11-09 Thread Ihor Radchenko
alain.coch...@unistra.fr writes:

> PS: there are a few occurrences of 'sub-tree' in the manual, but many
> of 'subtree'; I suggest to use 'subtree' everywhere -- better
> regarding searching.

Good point.
Fixed on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=044f09aa6de8f1f38de0f9b517510690807b4ef2

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] EXPORT_FILE_NAME keyword is used by `org-export-output-file-name' before macro expansion/INCLUDEs/removing COMMENTed trees (was: Confused about what the COMMENT keyword means)

2022-11-09 Thread Ihor Radchenko
Ihor Radchenko  writes:

> There should be no other buffer setting that is taken into account
> in COMMENTed subtrees. EXPORT_FILE_NAME is the only one.
>
> I think that we should not really change the manual unless we have to.
> It will be better to fix the bug instead.

I am attaching a tentative change to ox.el machinery that will allow
calculating EXPORT_FILE_NAME dynamically inside the processed export
buffer.

The change is not yet fixing the bug. I just want to hear feedback
on the approach I used.

Let me know if you see any issues or have better ideas.

>From 57aa366e9d5596741c256688c9b8ef07a9b24e17 Mon Sep 17 00:00:00 2001
Message-Id: <57aa366e9d5596741c256688c9b8ef07a9b24e17.1668044888.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Thu, 10 Nov 2022 09:39:20 +0800
Subject: [PATCH] org-export: Allow export file name to be determined after
 export processing

* lisp/ox.el (org-export-as): When :output-file info property is set
to a list, calculate :output-file after expanding macros, removing
uninterpreted data, and other processing.  Use the list value is used
as argument list for `org-export-output-file-name'.  Add new optional
argument WITH-INFO to return the info channel in addition to the
export string.
(org-export-to-file): Allow FILE argument to be an argument list to be
passed to `org-export-output-file-name' in the processed export
buffer.

This patch allows calculating the output file name after expanding all
the macros, cleaning up commented trees, and other export processing.
In particular, #+EXPORT_FILE_NAME keywords inside commented trees can
be ignored in contrast to what `org-export-output-file-name' returns
on the original Org file.

This patch is not changing any existing behavior and not fixing the
reported byg.  The callers of `org-export-to-file' still need to
change FILE argument to make use of the changes herein.

Reported-by: alain.coch...@unistra.fr
Link: https://orgmode.org/list/25422.27044.980916.495...@gargle.gargle.howl
---
 lisp/ox.el | 59 ++
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 770f86740..82cf0d166 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2994,7 +2994,8 @@ (defun org-export--remove-uninterpreted-data (data info)
 
 ;;;###autoload
 (defun org-export-as
-(backend  subtreep visible-only body-only ext-plist)
+(backend
+  subtreep visible-only body-only ext-plist with-info)
   "Transcode current Org buffer into BACKEND code.
 
 BACKEND is either an export back-end, as returned by, e.g.,
@@ -3020,7 +3021,10 @@ (defun org-export-as
 with external parameters overriding Org default settings, but
 still inferior to file-local settings.
 
-Return code as a string."
+Return code as a string.
+
+When optional argument WITH-INFO is non-nil, return a cons cell with car
+containing return code string and cdr containing the info channel."
   (when (symbolp backend) (setq backend (org-export-get-backend backend)))
   (org-export-barf-if-invalid-backend backend)
   (org-fold-core-ignore-modifications
@@ -3106,6 +3110,14 @@ (defun org-export-as
 			 p
 			 (org-export--remove-uninterpreted-data value info
 	   (_ nil)))
+   ;; Update `:output-file' option if needed.
+   (let ((output-file (plist-get info :output-file)))
+ (when (and output-file (listp output-file))
+   (plist-put
+info :output-file
+(apply #'org-export-output-file-name
+   ;; `:output-file' contains argument list.
+   output-file
 	   ;; Install user's and developer's filters.
 	   (setq info (org-export-install-filters info))
 	   ;; Call options filters and update export options.  We do not
@@ -3155,10 +3167,13 @@ (defun org-export-as
 	 ;; Remove all text properties since they cannot be
 	 ;; retrieved from an external process.  Finally call
 	 ;; final-output filter and return result.
-	 (org-no-properties
-	  (org-export-filter-apply-functions
-	   (plist-get info :filter-final-output)
-	   output info)
+ (let ((final-output
+	(org-no-properties
+	 (org-export-filter-apply-functions
+	  (plist-get info :filter-final-output)
+	  output info
+   (if with-info (cons final-output info)
+ final-output)
 
 ;;;###autoload
 (defun org-export-string-as (string backend  body-only ext-plist)
@@ -6637,7 +6652,10 @@ (defun org-export-to-file
 BACKEND is either an export back-end, as returned by, e.g.,
 `org-export-create-backend', or a symbol referring to
 a registered back-end.  FILE is the name of the output file, as
-a string.
+a string.  FILE can also be a list of options to determine file name
+automatically.  The options will be used as arguments of
+`org-export-output-file-name', which will be called right before

Re: [BUG] EXPORT_FILE_NAME keyword is used by `org-export-output-file-name' before macro expansion/INCLUDEs/removing COMMENTed trees (was: Confused about what the COMMENT keyword means)

2022-10-18 Thread Alain . Cochard
alain.coch...@unistra.fr writes on Tue 11 Oct 2022 16:42:
 > Ihor Radchenko writes on Sun  2 Oct 2022 12:48:
 > 
 >  > I recommend you to use :EXPORT_FILE_NAME: headline property and export
 >  > using subtree scope.
 > 
 > Thanks a lot for the tip.  A suggestion: that the :TITLE: property
 > be used if it exists.

Well, I just read about the EXPORT_ prefix properties for subtree
export, hence realized that the :EXPORT_TITLE: property can be used
for what I had in mind above.

PS: there are a few occurrences of 'sub-tree' in the manual, but many
of 'subtree'; I suggest to use 'subtree' everywhere -- better
regarding searching.


-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.coch...@unistra.fr
5 rue René Descartes   [bureau 110]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France | [ slot available for rent ]




Re: [BUG] EXPORT_FILE_NAME keyword is used by `org-export-output-file-name' before macro expansion/INCLUDEs/removing COMMENTed trees (was: Confused about what the COMMENT keyword means)

2022-10-11 Thread Alain . Cochard
Ihor Radchenko writes on Sun  2 Oct 2022 12:48:

 > I recommend you to use :EXPORT_FILE_NAME: headline property and export
 > using subtree scope.

Thanks a lot for the tip.  A suggestion: that the :TITLE: property be
used if it exists.


 > > I can only hope that the "observed inconsistency" related to
 > > EXPORT_FILE_NAME can be resolved.

 > Well. I do consider this a bug. However, it is not easy to fix.
 > [...]
 > I think that we should not really change the manual unless we have
 > to.  It will be better to fix the bug instead.

Yes, but if the bug is difficult to fix, it might be fixed only in a
long time (if ever).  In the mean time, I would say it is better to
warn the user.

-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.coch...@unistra.fr
5 rue René Descartes   [bureau 106]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France | [ slot available for rent ]




[BUG] EXPORT_FILE_NAME keyword is used by `org-export-output-file-name' before macro expansion/INCLUDEs/removing COMMENTed trees (was: Confused about what the COMMENT keyword means)

2022-10-01 Thread Ihor Radchenko
alain.coch...@unistra.fr writes:

> I can only hope that the "observed inconsistency" related to
> EXPORT_FILE_NAME can be resolved.

Well. I do consider this a bug. However, it is not easy to fix.
`org-export-output-file-name' is used across all ox-*.el backends,
including third-party packages, and it is called before we can determine
which parts of the exported file are going to be really exported.

I recommend you to use :EXPORT_FILE_NAME: headline property and export
using subtree scope.

> I still feel that section 13.6 of the manual can only been interpreted
> as: COMMENTing a tree is equivalent to commenting the tree.  I update
> my suggestion of addendum to the footnote:
>
>Note that the subtree is still parsed and '#+KEYWORD: value' pairs
>can contribute to calculation of buffer settings, in particular
>'#+EXPORT_FILE_NAME: value'.
> Incidentally, could you provide another example of a buffer setting
> that would be taken into account even in a COMMENTed subtree?  (I
> tried a few without success.)

There should be no other buffer setting that is taken into account
in COMMENTed subtrees. EXPORT_FILE_NAME is the only one.

I think that we should not really change the manual unless we have to.
It will be better to fix the bug instead.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92

Confirmed.