* ox.el (org-export-to-file): `write-region' instead of `write-file'. * ox-odt.el (org-odt-template, org-odt--export-wrap): `write-region' instead of `save-buffer'.
`write-file' and `save-buffer' trigger major mode changes, which leads to various mode-related hooks being run. This is undesirable: running these on generated files is wasted time and computation, and it can even lead to hard to track data corruption when auto-formatting hooks are involved. One such case is the 2006 version of the tidy program which ships with stock macOS and can corrupt multi-byte UTF-8 codepoints in HTML and ODT (via XML) exports. And even recent versions of tidy can re-arrange whitespace in the exported documents in unwanted ways. TINYCHANGE --- lisp/ox-odt.el | 4 ++-- lisp/ox.el | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 7f2e8ba47..6a8e75e9d 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -1427,7 +1427,7 @@ original parsed data. INFO is a plist holding export options." (level (string-to-number (match-string 2)))) (if (wholenump sec-num) (<= level sec-num) sec-num)) (replace-match replacement t nil)))) - (save-buffer 0))) + (write-region nil nil buffer-file-name))) ;; Update content.xml. (let* ( ;; `org-display-custom-times' should be accessed right @@ -4018,7 +4018,7 @@ contextual information." ;; Prettify output if needed. (when org-odt-prettify-xml (indent-region (point-min) (point-max))) - (save-buffer 0))))) + (write-region nil nil buffer-file-name))))) ;; Run zip. (let* ((target --out-file) (target-name (file-name-nondirectory target)) diff --git a/lisp/ox.el b/lisp/ox.el index 2a3edaa50..8ec1e25ee 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -6459,18 +6459,14 @@ or FILE." `(let ((output (org-export-as ',backend ,subtreep ,visible-only ,body-only - ',ext-plist))) - (with-temp-buffer - (insert output) - (let ((coding-system-for-write ',encoding)) - (write-file ,file))) + ',ext-plist)) + (coding-system-for-write ',encoding)) + (write-region output nil ,file) (or (ignore-errors (funcall ',post-process ,file)) ,file))) (let ((output (org-export-as - backend subtreep visible-only body-only ext-plist))) - (with-temp-buffer - (insert output) - (let ((coding-system-for-write encoding)) - (write-file file))) + backend subtreep visible-only body-only ext-plist)) + (coding-system-for-write encoding)) + (write-region output nil file) (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output)) (org-kill-new output)) ;; Get proper return value. -- 2.34.1