emacs-devel
[Top][All Lists]
Advanced

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

Misery with undo. Help, please!


From: Alan Mackenzie
Subject: Misery with undo. Help, please!
Date: Mon, 20 Oct 2008 19:06:26 +0000
User-agent: Mutt/1.5.9i

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 via email to

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