bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Lars Ingebrigtsen
Subject: bug#34720: 26.1; Reverting a GPG buffer moves all markers to the end of the file
Date: Mon, 26 Aug 2019 10:14:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

> Markers cannot be preserved in every situation, there's no way around
> this basic fact.

No, but commands like `revert-buffer' (via insert-file-contents) try to
keep most of them around.

> replace-buffer-contents is a primitive, so it can legitimately rely on
> Lisp programs to set up whatever preconditions it needs for it to
> work.  It MUST have a buffer to work with; if you want to replace with
> a string, insert that string into a buffer and call the primitive.
> Why is that a problem?

Why MUST it have a buffer to get the input data from?

You get a text from somewhere, and it often ends up in a string (as in
the epa case).  If you want to safely feed that to this function, you
have to say something along the lines of

(let ((buffer (current-buffer)))
  (with-temp-buffer
    (insert string)
    (let ((temp (current-buffer)))
      (with-current-buffer buffer
        (replace-buffer-contents temp)))))

which is horrible, horrible, and horrible.  No wonder this function has
gotten one single usage after it was introduced two years ago.  (Well,
one usage to replace-region-contents, which then calls the function.)
(Unless I'm grepping wrong.)

>> Would anybody mind if I just write a `with-saved-markers' macro in
>> subr-x, which would make all these problems to away and make the
>> solution a two-liner in epa itself?
>
> What would that macro do, exactly?

Gather the markers, execute the body, and then put the markers back
where they were.  Which is what replace-buffer-contents does, but for a
whole lot more stuff.

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]