Benjamin McMillan <mcmilla...@gmail.com> writes:

> The org export backend is complicated compared to my debugging skills, but
> I have been able to determin the following.
> 1) The issue happens because of poly-org.
> 2) It happens with -q and a minimal configuration (org + poly-org in init).
> 3) It happens even exporting a minimal org file, like a heading "test" and
> the text "a"
> 4) It only happens with org-export-in-background t
> 5) With org-export-async-debug t the error given in *Org Export Process* is
> like:
>    Invalid read syntax: "#<", 6, 407
> ...

Thanks for reporting!
Does the attached patch fix your problem?

>From 0fcf1cc7bf764135214fe9f7ada1dbccffb1c0cd Mon Sep 17 00:00:00 2001
Message-ID: <0fcf1cc7bf764135214fe9f7ada1dbccffb1c0cd.1740312989.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Sun, 23 Feb 2025 13:10:00 +0100
Subject: [PATCH] org-export-async-start: Drop text properties from exported
 text

* lisp/org-element.el (org-element--generate-copy-script):
New keyword argument to drop text properties from buffer string when
copying.
* lisp/ox.el (org-export-async-start): Strip text properties from
script generated for async Emacs call.  Text properties are not
required there and may contain unreadable Elisp objects.

Reported-by: Benjamin McMillan <mcmilla...@gmail.com>
Link: https://orgmode.org/list/calo8a5u1u7qlo-zfu78zjqsm6bn_tvmxl-ye_6gqbmd+tsa...@mail.gmail.com
---
 lisp/org-element.el | 25 ++++++++++++++-----------
 lisp/ox.el          |  5 ++++-
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 5a7435581a..8e17af8cf6 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -533,13 +533,11 @@ (defconst org-element-ignored-local-variables
 to the new buffer.  Variables with an unreadable value are also
 ignored.")
 
-(cl-defun org-element--generate-copy-script (buffer
-                                             &key
-                                             copy-unreadable
-                                             drop-visibility
-                                             drop-narrowing
-                                             drop-contents
-                                             drop-locals)
+(cl-defun org-element--generate-copy-script
+    (buffer
+     &key
+     copy-unreadable drop-visibility drop-narrowing
+     drop-contents drop-text-properties drop-locals)
   "Generate a function duplicating BUFFER.
 
 The copy will preserve local variables, visibility, contents and
@@ -549,9 +547,10 @@ (cl-defun org-element--generate-copy-script (buffer
 When optional key COPY-UNREADABLE is non-nil, do not ensure that all
 the copied local variables will be readable in another Emacs session.
 
-When optional keys DROP-VISIBILITY, DROP-NARROWING, DROP-CONTENTS, or
-DROP-LOCALS are non-nil, do not preserve visibility, narrowing,
-contents, or local variables correspondingly.
+When optional keys DROP-VISIBILITY, DROP-NARROWING, DROP-CONTENTS,
+DROP-TEXT-PROPERTIES, or DROP-LOCALS are non-nil, do not preserve
+visibility, narrowing, contents, text properties of contents, or local
+variables correspondingly.
 
 The resulting function can be evaluated at a later time, from
 another buffer, effectively cloning the original buffer there.
@@ -560,7 +559,11 @@ (cl-defun org-element--generate-copy-script (buffer
   (declare-function org-fold-core--update-buffer-folds "org-fold-core" ())
   (require 'org-fold-core)
   (with-current-buffer buffer
-    (let ((str (unless drop-contents (org-with-wide-buffer (buffer-string))))
+    (let ((str (unless drop-contents
+                 (org-with-wide-buffer
+                  (if drop-text-properties
+                      (substring-no-properties (buffer-string))
+                    (buffer-string)))))
           (narrowing
            (unless drop-narrowing
              (if (org-region-active-p)
diff --git a/lisp/ox.el b/lisp/ox.el
index 646d09b51e..7d44c3d702 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -6701,7 +6701,10 @@ (defun org-export-async-start  (fun body)
   ;; buffer to a temporary file, as it may be too long for program
   ;; args in `start-process'.
   (with-temp-message "Initializing asynchronous export process"
-    (let ((copy-fun (org-element--generate-copy-script (current-buffer)))
+    (let ((copy-fun (org-element--generate-copy-script
+                     ;; Text properties may contain unreadable Elisp
+                     ;; objects. Avoid them.
+                     (current-buffer) :drop-text-properties t))
           (temp-file (make-temp-file "org-export-process")))
       (let ((coding-system-for-write 'emacs-internal))
         (write-region
-- 
2.47.1

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
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>

Reply via email to