From f1ff68920c417343fda4c5a6450567d703ccf9b6 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Mon, 8 Jul 2024 13:52:32 +0200 Subject: [PATCH 1/2] ox: New custom option to disable macro replacement * lisp/ox.el (org-export-replace-macros): New custom option controlling macro replacement. (org-export--annotate-info): Honor it, except when processing inline code block results and their {{{results...}}} macro. * etc/ORG-NEWS (Allow disabling macro replacement during export): Announce the new option. * doc/org-manual.org (Macro Replacement): (Summary of the export process): Document the new option. --- doc/org-manual.org | 11 +++++++---- etc/ORG-NEWS | 9 +++++++++ lisp/ox.el | 13 +++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index d30c18e0c..5f5104f91 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -12682,9 +12682,11 @@ ** Macro Replacement #+cindex: @samp{MACRO}, keyword #+vindex: org-export-global-macros -Macros replace text snippets during export. Macros are defined -globally in ~org-export-global-macros~, or document-wise with the -following syntax: +#+vindex: org-export-replace-macros +Macros replace text snippets during export[fn::The macro replacement +can be disabled by setting ~org-export-replace-macros~ to nil (default +is t).]. Macros are defined globally in ~org-export-global-macros~, +or document-wise with the following syntax: : #+MACRO: name replacement text; $1, $2 are arguments @@ -16702,7 +16704,8 @@ *** Summary of the export process 3. Remove commented subtrees in the whole buffer (see [[*Comment Lines]]); -4. Replace macros in the whole buffer (see [[*Macro Replacement]]); +4. Replace macros in the whole buffer (see [[*Macro Replacement]]), + unless ~org-export-replace-macros~ is nil; 5. When ~org-export-use-babel~ is non-nil (default), process code blocks: diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 0c3b14128..dcd324115 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -43,6 +43,15 @@ or newer. # adding new customizations, or changing the interpretation of the # existing customizations. +*** Allow disabling macro replacement during export + +New custom option ~org-export-replace-macros~ controls whether Org +mode replaces macros in the buffer before export. Set it to nil to +disable macro replacement. + +This variable has no effect on the ={{{results...}}}= macros for inline +code block results. + *** Allow headline/olp target in ~org-capture-templates~ to be a function/variable The variable ~org-capture-templates~ accepts a target specification as diff --git a/lisp/ox.el b/lisp/ox.el index 6fa21be90..902c9f089 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -860,6 +860,14 @@ (defcustom org-export-expand-links t :package-version '(Org . "9.7") :type 'boolean) +(defcustom org-export-replace-macros t + "When non-nil, replace macros before export. +This variable does not affect {{{results}}} macros when processing +code block results." + :group 'org-export-general + :package-version '(Org . "9.8") + :type 'boolean) + (defcustom org-export-snippet-translation-alist nil "Alist between export snippets backends and exporter backends. @@ -3048,8 +3056,9 @@ (defun org-export--annotate-info (backend info &optional subtreep visible-only e (org-export-backend-name backend)) (org-export-expand-include-keyword nil nil nil nil (plist-get info :expand-links)) (org-export--delete-comment-trees) - (org-macro-initialize-templates org-export-global-macros) - (org-macro-replace-all org-macro-templates parsed-keywords) + (when org-export-replace-macros + (org-macro-initialize-templates org-export-global-macros) + (org-macro-replace-all org-macro-templates parsed-keywords)) ;; Refresh buffer properties and radio targets after previous ;; potentially invasive changes. (org-set-regexps-and-options) -- 2.45.2