When exporting an Org file asynchronously, the entire contents of that file are included as a string within the temp org-export-process file (see the implementation of org-export-async-start). Because this is a string, any double quotes within the original Org file are escaped with a backslash.
This results in an Elisp file that ends in
,----
| * Local variables
| # Local Variables:
| # eval: (setq org-src-block-faces (remove '(\"python\" (:background
\"#18314c\" :extend t)) org-src-block-faces))
| # End:
| ") (drop-visibility))]) (restore-buffer-modified-p nil) (print (let ((output
(org-export-as 'latex nil nil nil '(:output-file "example.tex"))))
(with-temp-buffer (insert output) (unless (bolp) (insert "
| ")) (let ((coding-system-for-write 'utf-8-unix)) (write-region nil nil
"example.tex"))) (or (ignore-errors (funcall 'org-latex-compile "example.tex"))
"example.tex"))))
`----
As part of the load process hack-local-variables--find-variables is called on
this file, and it mistakes this text for a local variables footer.
It tries to parse this but fails due to the backslashes:
,----
| Error: invalid-read-syntax ("#18314c" 1 75)
| read(#<buffer *temp*>)
| hack-local-variables--find-variables()
| hack-read-symbol-shorthands()
|
load-with-code-conversion("/private/var/folders/2h/g8xcqksj66lbvx75h4kz36br0000gn/T/org-export-processV56gnC"
"/private/var/folders/2h/g8xcqksj66lbvx75h4kz36br0000gn/T/org-export-processV56gnC"
nil t)
| command-line-1(("-l"
"/var/folders/2h/g8xcqksj66lbvx75h4kz36br0000gn/T/org-export-processV56gnC"))
| command-line()
| normal-top-level()
`----
(As a side note, when reproducing this I also realized that
org-export-async-start incorrectly assumes the existence of either
user-init-file or org-export-async-init-file.)
My proposal is to "disable" the invocation of the
hack-read-symbol-shorthands-function when loading the org-export-proceess temp
file. Note that buffer local variables of the org mode buffer are already
handled by org-element--generate-copy-script.
I have attached a diff showing a fix, although I am requesting feedback as I
think there's probably a better way to accomplish the same thing.
Minimal reproducible example:
example.org:
,----
| * Local variables
| # Local Variables:
| # eval: (setq org-src-block-faces (remove '("python" (:background "#18314c"
:extend t)) org-src-block-faces))
| # End:
`----
init.el (evaled manually):
,----
| (add-to-list 'load-path "~/Personal/oss/org-mode/lisp")
| (load-library "org")
| (setq org-export-async-debug t)
| (setq debug-on-error t)
`----
with emacs -nw -q
Version used:
Org mode version 10.0-pre (release_9.8-25-gc5cbb8 @
~/Personal/oss/org-mode/lisp/)
GNU Emacs 30.2.50 (build 1, aarch64-apple-darwin24.6.0, Carbon Version 170
AppKit 2575.7)
diff --git c/lisp/ox.el w/lisp/ox.el
index 686ffee..b77a2dc 100644
--- c/lisp/ox.el
+++ w/lisp/ox.el
@@ -6747,8 +6747,13 @@ and `org-export-to-file' for more specialized functions."
;; Text properties may contain unreadable Elisp
;; objects. Avoid them.
(current-buffer) :drop-text-properties t))
+ (bugfix-file (make-temp-file "hack-local-variables-hack"))
(temp-file (make-temp-file "org-export-process")))
(let ((coding-system-for-write 'emacs-internal))
+ (write-region
+ ";; -*- coding: utf-8-emacs-unix; lexical-binding:t -*-
+(setq hack-read-symbol-shorthands-function `(lambda (&rest args) (unless (string-match-p \"org-export-process\" load-file-name) (apply ,hack-read-symbol-shorthands-function args))))"
+ nil bugfix-file nil 'silent)
(write-region
;; Null characters (from variable values) are inserted
;; within the file. As a consequence, coding system for
@@ -6783,6 +6788,7 @@ and `org-export-to-file' for more specialized functions."
(if org-export-async-init-file
(list "-Q" "-l" org-export-async-init-file)
(list "-l" user-init-file))
+ (list "-l" bugfix-file)
(list "-l" temp-file)))))
;; Register running process in stack.
(org-export-add-to-stack (get-buffer proc-buffer) nil process)
signature.asc
Description: PGP signature
