Subject: Re: bug#28622: 25.1; EasyPG conflicts with tar-mode

From: Lars Ingebrigtsen <[email-masked]>
Date: Fri, 05 Feb 2021 11:19:40 +0100

Adam Tack <[email-masked]> writes:

> The issue is also present in emacs 24.5.1 and 26.1 (latest from git -
> 5659b2fe843627aa4b6d450758f71920143ac173).
>
> I think that the problem is caused by the fact that
> `epa-file-write-region' (which is used when saving buffers
> corresponding to `.gpg' files), does not call any of the
> `write-region-annotate-functions', directly or indirectly.
>
> `tar-mode' normally uses `tar-write-region-annotate' (which is added
> to `write-region-annotate-functions') to select the tar data buffer
> instead of the buffer containing the file listing, when saving.

Indeed.

The documentation of `write-region-annotate-functions' is nice...

----

A list of functions to be called at the start of ‘write-region’.
Each is passed two arguments, START and END as for ‘write-region’.
These are usually two numbers but not always; see the documentation
for ‘write-region’.  The function should return a list of pairs
of the form (POSITION . STRING), consisting of strings to be effectively
inserted at the specified positions of the file being written (1 means to
insert before the first byte written).  The POSITIONs must be sorted into
increasing order.

If there are several annotation functions, the lists returned by these
functions are merged destructively.  As each annotation function runs,
the variable ‘write-region-annotations-so-far’ contains a list of all
annotations returned by previous annotation functions.

An annotation function can return with a different buffer current.
Doing so removes the annotations returned by previous functions, and
resets START and END to ‘point-min’ and ‘point-max’ of the new buffer.

----

... but the only implementation of this algorithm is in C, spread out
over build_annotations and a_write.  :-/

Exposing any of that to the Lisp level doesn't seem practical (after
looking at the code for a couple of minutes), so if this is to work for
epa, then a Lisp implementation has to be written.

Before embarking on that -- has anybody looked at this before?  And
hopefully have an implementation somewhere they've just forgotten to
push?  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no