unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 34720@debbugs.gnu.org, dunni@gnu.org
Subject: bug#34720: 26.1; Reverting a GPG buffer moves all markers to the end of the file
Date: Tue, 27 Aug 2019 09:14:22 +0200	[thread overview]
Message-ID: <87v9uj2i7l.fsf@gnus.org> (raw)
In-Reply-To: <83pnksfel0.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 26 Aug 2019 12:42:03 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

> IOW, there's no guarantee that markers will be preserved across
> operations that replace text.

No, but we have a small handful of functions that do best effort...  but
they're deep in the C code and not accessible.

Finsert_file_contents has this:

  /* Replacement should preserve point as it preserves markers.  */
  if (!NILP (replace))
    {
      window_markers = get_window_points_and_markers ();
      record_unwind_protect (restore_point_unwind,
			     XCAR (XCAR (window_markers)));
    }
    ...
 handled:

  if (inserted > 0)
    restore_window_points (window_markers, inserted,
			   BYTE_TO_CHAR (same_at_start),
			   same_at_end_charpos);

The problem that this bug report addresses is that Lisp level functions
that implement special handlers for insert-file-contents (in this case,
epa-file-insert-file-contents) doesn't have access to the internals
necessary to give the user the same experience that the built-in version
gives the user.

My suggestion is basically to make DEFUN shims over
get_window_points_and_markers/restore_window_points, and create a new
macro `with-saved-markers' that would use that pair to do this cheap,
best-effort thing that Finsert_file_contents does.

> But I'm not opposed to adding support for string as the source for
> replacement.  Just be aware that the code which access such a string
> must be highly optimized, because it is executed in the innermost loop
> of the code.

I just had a peek at the code, and it indeed highly optimised...

>> 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.)
>
> replace-region-contents is used in json.el.

Yes, that's the one single usage of this machinery.

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





  reply	other threads:[~2019-08-27  7:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-03 15:28 bug#34720: 26.1; Reverting a GPG buffer moves all markers to the end of the file Ian Dunn
2019-07-09 16:33 ` Lars Ingebrigtsen
2019-08-26  7:20   ` Lars Ingebrigtsen
2019-08-26  7:59     ` Eli Zaretskii
2019-08-26  8:14       ` Lars Ingebrigtsen
2019-08-26  9:42         ` Eli Zaretskii
2019-08-27  7:14           ` Lars Ingebrigtsen [this message]
2019-08-27  8:00             ` Eli Zaretskii
2019-08-27  8:23               ` Lars Ingebrigtsen
2019-08-27  8:41                 ` Eli Zaretskii
2019-08-27  9:05                   ` Lars Ingebrigtsen
2019-08-27  9:17                     ` Eli Zaretskii
2019-08-27  9:15                   ` Lars Ingebrigtsen
2019-08-27 10:20                     ` Eli Zaretskii
2019-08-30  9:48                       ` Lars Ingebrigtsen
2019-08-30 10:21                         ` Lars Ingebrigtsen
2019-08-30 12:19                         ` Eli Zaretskii
2019-08-27  8:37               ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9uj2i7l.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=34720@debbugs.gnu.org \
    --cc=dunni@gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).