all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Misery with undo.  Help, please!
@ 2008-10-20 19:06 Alan Mackenzie
  2008-10-20 21:49 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2008-10-20 19:06 UTC (permalink / raw)
  To: Richard Stallman, emacs-devel

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).




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-23 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-20 19:06 Misery with undo. Help, please! Alan Mackenzie
2008-10-20 21:49 ` Andreas Schwab
2008-10-21 20:34   ` Alan Mackenzie
2008-10-23 18:33     ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.