emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Lukes <dafydd.lukes@gmail.com>
To: dafydd.lukes@gmail.com
Cc: emacs-orgmode@gnu.org
Subject: [PATCH] ox.el: Protect export from auto-formatting hooks
Date: Tue, 21 Jun 2022 14:36:06 +0200	[thread overview]
Message-ID: <20220621123606.162399-1-dafydd.lukes@gmail.com> (raw)
In-Reply-To: <CAEPTPEybHVvdTwc_-iwFp7Nrt1s88oWpuLfOcTmCYS+u977XDw@mail.gmail.com>

* ox.el, ox-odt.el: Use `write-region' instead of `write-file' or
`save-buffer' to protect generated export buffers from auto-formatting

In particular, `tidy' is often configured as the auto-formatter for HTML
and XML, and it can corrupt the exports.

 lisp/ox-odt.el | 4 ++--
 lisp/ox.el     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 9d47067..ec1c360 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -1411,7 +1411,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
@@ -4004,7 +4004,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 c75357b..66d18c4 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -6553,14 +6553,14 @@ or FILE."
 		 (insert output)
 		 (let ((coding-system-for-write ',encoding))
-		   (write-file ,file)))
+		   (write-region nil nil ,file)))
 	       (or (ignore-errors (funcall ',post-process ,file)) ,file)))
         (let ((output (org-export-as
                        backend subtreep visible-only body-only ext-plist)))
             (insert output)
             (let ((coding-system-for-write encoding))
-	      (write-file file)))
+	      (write-region nil nil file)))
           (when (and (org-export--copy-to-kill-ring-p) (org-string-nw-p output))
             (org-kill-new output))
           ;; Get proper return value.

  reply	other threads:[~2022-06-21 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 16:29 Protect Org export from auto-formatting hooks David Lukeš
2022-02-26  9:32 ` Nicolas Goaziou
2022-02-28 13:14   ` David Lukeš
2022-02-28 13:23     ` Nicolas Goaziou
2022-02-28 13:42       ` David Lukeš
2022-06-21 12:36         ` David Lukes [this message]
2022-06-21 12:46           ` [PATCH] ox.el: Protect " David Lukeš

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220621123606.162399-1-dafydd.lukes@gmail.com \
    --to=dafydd.lukes@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).