unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Richard Stallman <rms@gnu.org>, emacs-devel@gnu.org
Subject: Misery with undo.  Help, please!
Date: Mon, 20 Oct 2008 19:06:26 +0000	[thread overview]
Message-ID: <20081020190626.GA3558@muc.de> (raw)

Hi, Richard and Emacs!

I'm having a very bad day, and help would be appreciated.  The following
scenario arose in my investigation of bug#1202:

Open a fresh buffer in fundamental mode.  Type in "GNU" (three letters).
Then look at the undo list, M-: buffer-undo-list

    (nil (1 . 4) (t 65535 . 65535))

.  The three elements are:
   nil          ; undo boundary
   (1 . 4)      ; beginning and end of "GNU"
   (t 65535 .65535) ; Timestamp of file (here, there isn't one).

In this state, you can undo with C-_ (or whatever).

Now prefix a POSITION element and another undo boundary with
M-: (push (point) buffer-undo-list
M-: (push nil buffer-undo-list)

buffer-undo-list now looks like

    (nil 4 nil (1 . 4) (t 65535 . 65535))  [*]

, where the extra two elements are:
   nil           ; undo boundary
   4             ; POSITION.

[*] Actually, it inserts an extra, spurious, nil too, or I've badly
misunderstood something.  This seems to be a bug in the macro `push'.  Do
M-: (pop buffer-undo-list) to get rid of this.  I'm having a bad day.
:-(

o-o-O-o-o-O-o-o-O-o-o

If you now attempt an undo, point is indeed moved to bufpos 4, but
buffer-undo-list doesn't lose its first two elements as it should.  THIS
IS A BUG.

o-o-O-o-o-O-o-o-O-o-o

However, if you do M-2 C-_, the (double) undo works, but buffer-undo-list
now looks like:

   (nil
    ("GNU" . 1)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    (#<marker at 1 in GNU> . -3)
    nil
    4
    nil
    (1 . 4)
    (t 65535 . 65535))

[The #<marker ... elements mean "this marker was shifted this number of
characters forward in the change."]

    (eq (car (nth 2 buffer-undo-list)) (car (nth 3 buffer-undo-list)))
evaluates to nil, suggesting that 12 markers (not merely 12 copies of a
single marker) have been created and inserted into buffer-undo-list.  I
have a suspicion this is a bug.  I can't be sure.  When I attempt C-x
C-x, Emacs says "No mark set in this buffer".

o-o-O-o-o-O-o-o-O-o-o

I've tried to track all this down for several hours, and only got very
confused and miserable.  Help would be appreciated.

When buffer changes are made, Emacs pushes stuff onto buffer-undo-list (a
buffer local global variable) directly, each primitive calling one of the C
functions such as record_insert (in ..../src/undo.c).  This is fine.

When `undo' is invoked, things aren't quite so simple.  buffer-undo-list
is first copied into pending-undo-list, some changes are undone,
(possibly pushing more stuff onto buffer-undo-list), and finally, L1670,
after this comment:

    ;; Don't specify a position in the undo record for the undo command.
    ;; Instead, undoing this should move point to where the change is.

, trims POSITION elements from b-u-l, up to the first undo boundary.

Richard, some while ago, you added in this bit which trims these POSITION
elements.  This was in simple.el V1.121.  Can you remember why you did
this?  It kind of feels to me that there might have been some problem
with POSITIONs in `primitive_undo', and this was a temporary kludge to
get round it.  Can you remember?  It was only 14 years 7 months ago.
(Don't you just love VCSs? :-).

Help, please.

-- 
Alan Mackenzie (Nuremberg, Germany).




             reply	other threads:[~2008-10-20 19:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20 19:06 Alan Mackenzie [this message]
2008-10-20 21:49 ` Misery with undo. Help, please! Andreas Schwab
2008-10-21 20:34   ` Alan Mackenzie
2008-10-23 18:33     ` Stefan Monnier

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=20081020190626.GA3558@muc.de \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=rms@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).