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 WNJIIxT0GWKMygAAgWs5BA (envelope-from ) for ; Sat, 26 Feb 2022 10:34:12 +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 wNS4IBT0GWKfDgEA9RJhRA (envelope-from ) for ; Sat, 26 Feb 2022 10:34:12 +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 2C4D23A103 for ; Sat, 26 Feb 2022 10:34:12 +0100 (CET) Received: from localhost ([::1]:50564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNtSr-0006Ck-FT for larch@yhetil.org; Sat, 26 Feb 2022 04:34:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNtQy-0006CL-9B for emacs-orgmode@gnu.org; Sat, 26 Feb 2022 04:32:15 -0500 Received: from [2001:4b98:dc4:8::221] (port=42055 helo=relay1-d.mail.gandi.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNtQw-00031Q-1Y for emacs-orgmode@gnu.org; Sat, 26 Feb 2022 04:32:11 -0500 Received: (Authenticated sender: admin@nicolasgoaziou.fr) by mail.gandi.net (Postfix) with ESMTPSA id 2D3D1240007; Sat, 26 Feb 2022 09:32:02 +0000 (UTC) From: Nicolas Goaziou To: David =?utf-8?Q?Luke=C5=A1?= Subject: Re: Protect Org export from auto-formatting hooks References: Mail-Followup-To: David =?utf-8?Q?Luke=C5=A1?= , emacs-orgmode@gnu.org Date: Sat, 26 Feb 2022 10:32:02 +0100 In-Reply-To: ("David =?utf-8?Q?Luke=C5=A1=22's?= message of "Fri, 25 Feb 2022 17:29:06 +0100") Message-ID: <87pmnagei5.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:4b98:dc4:8::221 (failed) Received-SPF: pass client-ip=2001:4b98:dc4:8::221; envelope-from=mail@nicolasgoaziou.fr; helo=relay1-d.mail.gandi.net X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, 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: emacs-orgmode@gnu.org 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=1645868052; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5Z107hB6DRImOrsDv1UQEDBNyPgUHjKyO6oXx+D2218=; b=mQ09rViP4SBXEdDN9kUeXc1Hka0xtGX0yryWxiNxG/5od6D8Ikg5HBlZTErSdZIa78qFCA A7MRtFyqT5/+ZFisGIKURyX/ZY0Q4Tjf2miqbz5/9CvNBxehDB+k8svJE7NwB6Fs2qsquw WdNY/SDj22OXTyCc15eOYw42LgShfJq9EfPBl2fMvcNrkslF449Nd1+zTZzPIdSm0vGbUg PTkasm0AER9L2iCHWq/a9l772EXTq9hUeV6nVI5hGFZ+BDIFHy6v6tpLyTilagF9+wjtif gIfOdn/Rt6q3lGm+oY1pjVGJseSRlOLQOp4+vdsOVK02GSViCygmFqNytbiPTA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645868052; a=rsa-sha256; cv=none; b=IYaI1SgEZ34DZr5LUnsHobsyphgtR99hDF4/HaCPIrb6mZ0bMjL0F2zqvxIYBS9RdoiMQr 2HoBoGFF3FHXz0+6joMR2ZYv1UzDGbnpGtl9pHJKZ3wOgXIFolIOHhqPrqENlAOLMi8fLY P71lt3nCkVStMgYIcLSZj5gq58IHeISIqgo9q9EliSZwj2E8jsFqS4Xzcacg5SxpZ8KATe c7lhjU6SYZ8qUa9lyg1QdFmzsNd3oTDbHUlZbmby5a/VTn6Cs+7bFb74fWGvoUNwR2nz0V iNfck6cEulS6XV0kbAzcARZTQ5howFvPViF6VcmLv6zGV14h6qsUkGcRdgoc0w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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: -3.92 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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: 2C4D23A103 X-Spam-Score: -3.92 X-Migadu-Scanner: scn0.migadu.com X-TUID: rk4beL+FOegk Hello, David Luke=C5=A1 writes: > So I think Org should try to protect the export buffer from these > shenanigans as much as possible. The best way I can think of to achieve > that is to keep the export buffer in fundamental mode. This should > prevent all the mode-related code from running, potentially even making > the export speedier. > > After some experimenting, the way I finally got this to work was by > locally overriding the `set-auto-mode=E2=80=99 function: > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 diff --git a/lisp/ox.el b/lisp/ox.el > =E2=94=82 index 2a3edaa50..d5a77c26e 100644 > =E2=94=82 --- a/lisp/ox.el > =E2=94=82 +++ b/lisp/ox.el > =E2=94=82 @@ -6462,14 +6462,16 @@ or FILE." > =E2=94=82 ',ext-plist))) > =E2=94=82 (with-temp-buffer > =E2=94=82 (insert output) > =E2=94=82 - (let ((coding-system-for-write ',encoding)) > =E2=94=82 + (cl-letf ((coding-system-for-write ',encoding) > =E2=94=82 + ((symbol-function 'set-auto-mode) #'ignore)) > =E2=94=82 (write-file ,file))) > =E2=94=82 (or (ignore-errors (funcall ',post-process ,file)) ,fil= e))) > =E2=94=82 (let ((output (org-export-as > =E2=94=82 backend subtreep visible-only body-only > ext-plist))) > =E2=94=82 (with-temp-buffer > =E2=94=82 (insert output) > =E2=94=82 - (let ((coding-system-for-write encoding)) > =E2=94=82 + (cl-letf ((coding-system-for-write encoding) > =E2=94=82 + ((symbol-function 'set-auto-mode) #'igno= re)) > =E2=94=82 (write-file file))) > =E2=94=82 (when (and (org-export--copy-to-kill-ring-p) (org-st= ring-nw-p > output)) > =E2=94=82 (org-kill-new output)) > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > What are your thoughts? Is this desirable? In my mind, yes: even if > someone has configured auto-formatting manually, they might still not > realize it=E2=80=99s getting run in a hidden buffer they never get to see= . After > all, this is an implementation detail =E2=80=93 if Emacs had a built-in f= unction > to write a string to a file, I presume that would get used instead? > > (In a way, I was lucky that I encountered quite noticeable issues with > mangled characters. With the recent version of tidy, which only messes > up whitespace, I might not have noticed at all.) > > And if such protection is desirable, is this the best way to do it? Or > can you come up with a better approach? What about using `write-region' instead of `write-file' and not touching `set-auto-mode' function? Could you test it? Note the arguments are different, the equivalent to (write-file file) would be (write-region nil nil file). Regards, --=20 Nicolas Goaziou