From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 0JtQNCVZbGMH9wAAbAwnHQ (envelope-from ) for ; Thu, 10 Nov 2022 02:51:33 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4IxZNCVZbGMwqgAAauVa8A (envelope-from ) for ; Thu, 10 Nov 2022 02:51:33 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9FACF1CE9B for ; Thu, 10 Nov 2022 02:51:29 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oswiD-0003sJ-Og; Wed, 09 Nov 2022 20:50:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oswiA-0003qy-RS for emacs-orgmode@gnu.org; Wed, 09 Nov 2022 20:50:35 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oswi8-0001xj-2G for emacs-orgmode@gnu.org; Wed, 09 Nov 2022 20:50:34 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5265E240026 for ; Thu, 10 Nov 2022 02:50:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1668045028; bh=BJyqOk78CpS3cfHX5DK5HfbFKbdhuzHPB8isN8CV15Y=; h=From:To:Cc:Subject:Date:From; b=I/MQhRQte9AhMjRQlKZyURBcRIOC0BaaGK4vjPFbzJO5LJAJ8VDn3keYIezp7XAM/ SlCCIT50iMmKuX67HSI7vm8Xm6J2OowpNlUmKevOgekOS5AVtNZuWmKVGRo6w9oyHF h+74EdOlHop/YSkgzrT6SLv4eNjQa2kf5d4knldUFb1pfXbXNyw1VyY43xd+LJBQHk Y64DlhQZjCp108DFXxPJThtpDgYwh4a4X8zjiXOrwxOtUUMQQP7Oa7F2aEKGxEdcjJ 4I0Goh5053G4Co4B4L0t9GkKl5YnM/tlQuFLXLIFtZ2KAvxPJ20hUwg1NvFKfA3RxK MWT4uaNhF23RQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N74Xw31GNz9rxF; Thu, 10 Nov 2022 02:50:24 +0100 (CET) From: Ihor Radchenko To: Ihor Radchenko Cc: alain.cochard@unistra.fr, emacs-orgmode@gnu.org Subject: 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) In-Reply-To: <87k05i25lq.fsf@localhost> References: <25393.61240.135445.401251@gargle.gargle.HOWL> <87leq5pomk.fsf@localhost> <25394.40867.872373.589874@gargle.gargle.HOWL> <87o7v1nu2e.fsf@localhost> <25398.44905.256243.690039@gargle.gargle.HOWL> <87k05i25lq.fsf@localhost> Date: Thu, 10 Nov 2022 01:51:05 +0000 Message-ID: <874jv7lgqe.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1668045089; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=FQtIJ6MeM7/zPp1KQyl5iGFUCenFfpThRXKz9SzXR6E=; b=dMbjANpc67ibkwHzOntNBgehoyx1tDDbMz+dzJ/aTkwCxV93eEL4X/orxfkOb0xiDW/k/3 MwYT/0B/qpYqu5fA0EUErOiVwVOx8a6Pzg8RyZYbXS0B9cCnQiWZv6qiRPQAzc/qdl14/F OoclNM446WJEDx7cIz0O7MD+h5L9cEAOy+SkpkfcJot10uVdB0ijvTSo3UGeshSgQyCj9K DeOZPk0ubqJixL5QfckAYS7ozFgRc8AE87JKR6L5/2yf3zLXYIk+eU4wFgJQa3VBGM41Yy G80T4UguypWJTdzH+K2UViZS5K24eyOpMjw6iRp4+QI37o8gJpR1nXUGb2uffw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1668045089; a=rsa-sha256; cv=none; b=EDn5WL16CuGTXdOUmrnyX6RHrzFJIeCYs64NJH5V3vZQ7nPMTyNMFHDmLC/PMNBAsG61wB PAjXA5GfVmmS52fnDOW/hOHvFIsj+ZhzpRoZZ9Io8nUty34qutSnLh3U1E/AqxBDzj+vY3 6NqlvMq1Rqwead4BOlPcY96giLRkDJQZX5y+X8p+x7CHLNQXLe7roJfPI5Q+5ioA3hSxmQ CgdBBjK4tc7CD5I44iMJ/+4ReTqZCcgCoPiJviLYK7MYQ9/UcZdP2tSA/kvxvR+PNHRSGp G2ZPX2yErK7YtlTsi7MZyNgmhYTpNA0pwosMJ8zGaRQX7gv9QKFPnj1xIGesUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="I/MQhRQt"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.23 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="I/MQhRQt"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9FACF1CE9B X-Spam-Score: -2.23 X-Migadu-Scanner: scn1.migadu.com X-TUID: FIa9VePAnvhm --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-export-Allow-export-file-name-to-be-determined-a.patch >From 57aa366e9d5596741c256688c9b8ef07a9b24e17 Mon Sep 17 00:00:00 2001 Message-Id: <57aa366e9d5596741c256688c9b8ef07a9b24e17.1668044888.git.yantar92@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.Cochard@unistra.fr Link: https://orgmode.org/list/25422.27044.980916.495348@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 &optional subtreep visible-only body-only ext-plist) + (backend + &optional 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 &optional 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 +:filter-options filter inside the cleaned buffer to be exported. A non-nil optional argument ASYNC means the process should happen asynchronously. The resulting buffer will then be accessible @@ -6664,26 +6682,33 @@ (defun org-latex-export-to-latex POST-PROCESS needs to be quoted. The function returns either a file name returned by POST-PROCESS, -or FILE." +or FILE written." (declare (indent 2)) - (if (not (file-writable-p file)) (error "Output file not writable") + (if (and (stringp file) (not (file-writable-p file))) + (error "Output file not writable") (let ((ext-plist (org-combine-plists `(:output-file ,file) ext-plist)) (encoding (or org-export-coding-system buffer-file-coding-system))) (if async (org-export-async-start (lambda (file) (org-export-add-to-stack (expand-file-name file) backend)) - `(let ((output - (org-export-as - ',backend ,subtreep ,visible-only ,body-only - ',ext-plist))) + `(let* ((output + (org-export-as + ',backend ,subtreep ,visible-only ,body-only + ',ext-plist ,(when (listp file) 'with-info))) + (file ,(if (listp file) '(cdr output) file))) + (when (consp output) (setq output (car output))) (with-temp-buffer (insert output) (let ((coding-system-for-write ',encoding)) - (write-region (point-min) (point-max) ,file))) - (or (ignore-errors (funcall ',post-process ,file)) ,file))) - (let ((output (org-export-as - backend subtreep visible-only body-only ext-plist))) + (write-region (point-min) (point-max) file))) + (or (ignore-errors (funcall ',post-process file)) file))) + (let* ((output (org-export-as + backend subtreep visible-only + body-only ext-plist + (when (listp file) 'with-info))) + (file (if (listp file) (cdr output) file))) + (when (consp output) (setq output (car output))) (with-temp-buffer (insert output) (let ((coding-system-for-write encoding)) -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--