From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0O32HbDbHGIMbwEAgWs5BA (envelope-from ) for ; Mon, 28 Feb 2022 15:26:56 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SBM+G7DbHGI0sgAA9RJhRA (envelope-from ) for ; Mon, 28 Feb 2022 15:26:56 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F18A248D92 for ; Mon, 28 Feb 2022 15:26:55 +0100 (CET) Received: from localhost ([::1]:36064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOgzH-00025g-4g for larch@yhetil.org; Mon, 28 Feb 2022 09:26:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOgiA-0003No-86 for emacs-orgmode@gnu.org; Mon, 28 Feb 2022 09:09:14 -0500 Received: from [2a00:1450:4864:20::530] (port=33513 helo=mail-ed1-x530.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nOgi8-0007nS-MH for emacs-orgmode@gnu.org; Mon, 28 Feb 2022 09:09:13 -0500 Received: by mail-ed1-x530.google.com with SMTP id s14so17822269edw.0 for ; Mon, 28 Feb 2022 06:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6dp8JhmmNE+g9SGBNl7mKJHKGCBK2fNJm3LAuSvfKPI=; b=Xza7l3LcEThzEg1foo5Us7n+djMxDoPATS8fwreuJmI82M0k71ZPCMK97V7G27ygCb aGx2NILF1/MpbOYe0vkvSCVBTCWx/FkSb0wZAItNjK6O2xjZ8OYC2rdBBhfCPNQw8vCG 65ZWTE55+qufo6aSCsFlU5r1vKPTJC1BG9jlziJRhRd28dw4kw/7wb5gsRTt60MfA9K6 eGNFfgKU0WeUxUPmWTPMFbbX5vzD4Dr0kD7KCY1tBaT6x3rh4SKhr9hfOr+t3fb03cjE 38W/yz4druCU9wKHlwGY3KVGOhbtvgLG+Cymw9BH7kQG9ugwVRaUH/vEnHXu+46M1vLn viJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6dp8JhmmNE+g9SGBNl7mKJHKGCBK2fNJm3LAuSvfKPI=; b=1I1xbPuRkU/cNaKqFmiGLjBBqrzwdfLqTNL7HasPhD3j0IQSxkHe02EUY6RaZuELy/ eZDuzPdOSqSFaJhvW3uYyDutF5tzbXFUz5D9IavTzMaiWcrxWu4a+97GY6GvnxeF7QtU mwpXPQCJ/FThqDd5S9/P7u+jNjeJDN/u1FTYxmwJjB1gNI/w+17WoaU3R5Yn6v9tOC/C EhHnCNrKjD1+30zbHdAl8IlBlNQyc1VMFBvYLyGY+a5ootV11ftVPkoxyodPEoHgnJ/X Hz3RqIzGRXotJxkUwo7MAwvIY/XqsRgxrZcyOUMWXrzo5yj+94nwppOZFypNAsW+bU+/ orvw== X-Gm-Message-State: AOAM532KnCbrG4KvAcJFnxf2Sokd5pwwk2oghvXWvHhmOlW+KWJNoYiV cx/ZjB3t8swpCJipD7DmlT0f9mOXvKsvVA== X-Google-Smtp-Source: ABdhPJx0X+cvx1YEmAUCfNQmRYOWok5EMug7krP19u0y1HSnJQcv4FDawWGRxWevPI8wHSWZVhvaeg== X-Received: by 2002:a50:ee90:0:b0:40f:349f:7368 with SMTP id f16-20020a50ee90000000b0040f349f7368mr19276029edr.236.1646057350517; Mon, 28 Feb 2022 06:09:10 -0800 (PST) Received: from localhost.localdomain ([2001:718:1e03:ffc2:a03f:bf16:747:f550]) by smtp.gmail.com with ESMTPSA id y18-20020a056402271200b0041110d6b80asm6122920edd.39.2022.02.28.06.09.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 28 Feb 2022 06:09:09 -0800 (PST) From: David Lukes To: emacs-orgmode@gnu.org Subject: [PATCH] ox: Prevent auto-formatting in export buffers Date: Mon, 28 Feb 2022 15:07:50 +0100 Message-Id: <20220228140750.75761-1-dafydd.lukes@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::530 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=dafydd.lukes@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lukes Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1646058416; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=6dp8JhmmNE+g9SGBNl7mKJHKGCBK2fNJm3LAuSvfKPI=; b=Ld7B1+aQdrAaimrZtRycTCpoy7kEWUERJl6eXm0NsG4k8XzSAdRweYyk/gh6830djHFNrL OgqiPlZxcgLMNQiVlgbKucQi9FaIdqcnklIbhRJbZrWXVxsbcPkM/1TlGM5gmkCDkMocei 0OVDQPTspFrqtfPz2rzDH8v8IFcjBrUCIhbvaHCeS+Lix9Ad0EpQlad3ZWANgoRFWGV6Jn uVYcMziHYw8HBOAGpFtLg/9QU9b5eIEgnnRSl0ZO6a1NtJE7Jckj+BlRyOOK/ctPuS0Qnr CLpEAiawmV2uAn295zqbJcgT60m83ceEm7np4ZVs6rHRAr2aCLMLcQzT1b0nog== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1646058416; a=rsa-sha256; cv=none; b=FbGPU5ff6/KV6s8q4DSS52zJDUg5Jmgzaoa9QlhZqEqdU4Dl9iwls1pwOBrlYMdcFCzx4n XX1OU7Z2Wm4AUzEr86lQ5v0yDL2HAh1qx/nrT1mpn/Zhx6NXZxavUdsOpy5pIj7n01BOc4 hScOUz5QRt4KvZTUK8fjPyILvMLa76OKZuxj4vaM+PRzGnFZjfUaXTAN4/5y1SGgCa4POq QIsfu/C0Fhdhi7rIfR5ifFK/+aKP0eFesJVRkEbF624iYOhewg6a0iLV70F6RAwuIynrQX y/Sdg/fRlbw0jgtCt6L6GBXNCtNPyzDpIzql3fMQxDxv+BFLCVk3Xm+BTwL7Xg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Xza7l3Lc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.30 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Xza7l3Lc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: F18A248D92 X-Spam-Score: -7.30 X-Migadu-Scanner: scn0.migadu.com X-TUID: UZQbEUAMgIEy * 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