Subject: Re: bug#5440: 23.1; buffer-file-format encoding temp buffers not reentrant

From: Andrew Hyatt <[email-masked]>
Date: Mon, 25 Jul 2016 00:07:50 -0400

Eli Zaretskii <[email-masked]> writes:

>> From: Andrew Hyatt <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Sun, 24 Jul 2016 01:06:05 -0400
>> 
>> >  -- Variable: format-alist
>> >      This list contains one format definition for each defined file
>> >      format.            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> >      ^^^^^^
>> >
>> > "Only one format definition per format."  But I think it won't do any
>> > harm to specifically warn about violating that.
>> >
>> > Thanks.
>> 
>> I think the original bug report had one format definition for each
>> defined file format, but was manipulating a file in one format while in
>> another format function.
>
> That's more than one format in disguise.
>
>> How about I change the documentation to just warn not to manipulate
>> other files in FROM-FN here?
>
> Can you show a proposed patch?
>
> Thanks.

Attached.

>From 18eb654c4541a49f415d4826974fd2c216f2c2db Mon Sep 17 00:00:00 2001
From: Andrew Hyatt <[email-masked]>
Date: Sun, 24 Jul 2016 23:58:47 -0400
Subject: [PATCH] Warn against unintentional recursion in formatting.

Change documentation for format-alist to warn against formatting when
formatting, which leads to incorrect results..
---
 doc/lispref/files.texi | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index f3650a4..5763380 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -3238,7 +3238,9 @@ Format Conversion Round-Trip
 
 One responsibility of @var{from-fn} is to make sure that the beginning
 of the file no longer matches @var{regexp}.  Otherwise it is likely to
-get called again.
+get called again.  Also, @var{from-fn} must not involve other buffers or
+files other than the one being decoded, or else formatting may happen
+during formatting, leading to incorrect results.
 
 @item to-fn
 A shell command or function to encode data in this format---that is, to
@@ -3269,6 +3271,10 @@ Format Conversion Round-Trip
 positions.  All this takes place without modifying the buffer.
 @end itemize
 
+@var{to-fn} must not involve other buffers or files other than the one
+being encoded, or else formatting may happen during formatting,
+leading to incorrect results.
+
 @item modify
 A flag, @code{t} if the encoding function modifies the buffer, and
 @code{nil} if it works by returning a list of annotations.
-- 
2.4.9 (Apple Git-60)