Subject: Re: bug#34720: 26.1; Reverting a GPG buffer moves all markers to the end of the file

From: Eli Zaretskii <[email-masked]>
Date: Tue, 27 Aug 2019 12:17:11 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Tue, 27 Aug 2019 11:05:33 +0200
> 
> (progn
>   (find-file "/tmp/foo.txt")
>   (kill-buffer (current-buffer))
>   (when (file-exists-p "/tmp/foo.txt")
>     (delete-file "/tmp/foo.txt"))
>   (find-file "/tmp/foo.txt")
>   (insert "Test line.")
>   (setq test-marker1 (make-marker))
>   (move-marker test-marker1 4)
>   (setq test-marker2 (make-marker))
>   (move-marker test-marker2 5)
>   (save-buffer t)
>   (shell-command "echo new >> /tmp/foo.txt")
>   (revert-buffer nil t)
>   (list test-marker1 test-marker2))
> 
> => (#<marker at 4 in foo.txt> #<marker at 5 in foo.txt>)
> 
> So the markers seem to be restored on `revert-buffer'?

The original text is unchanged, you just added something at the end of
the file.  So markers at positions 4 and 5 will be preserved, yes.

> The reason this doesn't happen in the epa case seems to be a bug in
> Finsert_file_contents: When there's an external handler, it skips
> directly to handled: and neglects to do the same_at_start computation,
> which leaves that at point-min and restore_window_points ignores all
> markers that have values that are larger than same_at_start.

AFAIU, the problem with the epa case is that the buffer is erased and
the text re-inserted.  Isn't that the case?

In any case, how can insert-file-contents know what the handler did
wrt which part(s) of the buffer remained unchanged?

> If the new text doesn't match the old text, the markers are not
> restored:

Of course.