Previous: Implementation, Up: Undo Protocol
Class precedence list:
undo-mixin, standard-object, slot-object, t
Slots:
tree
Returns the undo-tree of the buffer.
undo-accumulate
The undo records created since the start of the undo context.
performing-undo
True if we are currently performing undo, false otherwise.
This is a mixin class that buffer classes can inherit from. It contains an undo tree, an undo accumulator and a flag specifyng whether or not it is currently performing undo. The undo tree and undo accumulators are initially empty.
The undo-tree object associated with the buffer. This usually contains a record of every change that has been made to the buffer since it was created.
Undo is implemented as :before methods on, insert-buffer-object, insert-buffer-sequence and delete-buffer-range specialized on undo-mixin.
A list of the changes that have been made to
buffer
since the last time undo was added to the undo tree for the buffer. The list returned by this function is initially NIL (the empty list). The :before methods oninsert-buffer-object
,insert-buffer-sequence
, anddelete-buffer-range
push undo records on to this list.
If true, the buffer is currently performing an undo operation. The :before methods on
insert-buffer-object
,insert-buffer-sequence
, anddelete-buffer-range
push undo records onto the undo accumulator only ifperforming-undo
is false, so that no undo information is added as a result of an undo operation.
Three subclasses insert-record
, delete-record
, and
compound-record
of undo-record are used. An insert record stores a
position and some sequence of objects to be inserted, a delete record
stores a position and the length of the sequence to be deleted, and a
compound record stores a list of other undo records.
The :before methods on insert-buffer-object
and
insert-buffer-sequence
push a record of type delete-record onto the
undo accumulator for the buffer, and the :before method on
delete-buffer-range
pushes a record of type insert-record
onto
the undo accumulator.
This macro executes the forms of
body
, registering changes made to the list of buffers retrieved by evaluatingget-buffers-exp
. Whenbody
has run, for each buffer it will calladd-undo
with an undo record and the undo tree of the buffer. If the changes done bybody
to the buffer has resulted in only a single undo record, it is passed as is toadd-undo
. If it contains several undo records, a compound undo record is constructed out of the list and passed toadd-undo
. Finally, if the buffer has no undo records,add-undo
is not called at all.
To avoid storing an undo record for each object that is inserted, the with-undo macro may in some cases just increment the length of the sequence in the last delete-record.
The method on flip-undo-record
specialized on insert-record
binds performing-undo
for the buffer to T
, inserts the
sequence of objects in the buffer, and calls change-class
to
convert the insert-record
to a delete-record
, giving it a the
length of the stored sequence.
The method on flip-undo-record
specialized on delete-record
binds performing-undo
for the buffer to T
, deletes the range
from the buffer, and calls change-class
to convert the
delete-record
to an insert-record
, giving it the sequence at
the stored offset in the buffer with the specified length.
The method on flip-undo-record
specialized on compound-record
binds performing-undo
for the buffer to T
, recursively calls
flip-undo-record
on each element of the list of undo records, and
finally destructively reverses the list.
Class precedence list:
drei-undo-record, standard-undo-record, undo-record, standard-object, slot-object, t
Slots:
buffer
— initargs::buffer
The buffer to which the record belongs.
A base class for all output records in Drei.
Class precedence list:
simple-undo-record, drei-undo-record, standard-undo-record, undo-record, standard-object, slot-object, t
Slots:
offset
— initargs::offset
The offset that determines the position at which the undo operation is to be executed.
A base class for output records that modify buffer contents at a specific offset.
Class precedence list:
insert-record, simple-undo-record, drei-undo-record, standard-undo-record, undo-record, standard-object, slot-object, t
Slots:
objects
— initargs::objects
The sequence of objects that are to be inserted whenever flip-undo-record is called on an instance of insert-record.
Whenever objects are deleted, the sequence of objects is stored in an insert record containing a mark.
Class precedence list:
delete-record, simple-undo-record, drei-undo-record, standard-undo-record, undo-record, standard-object, slot-object, t
Slots:
length
— initargs::length
The length of the sequence of objects to be deleted whenever
flip-undo-record
is called on an instance ofdelete-record
.Whenever objects are inserted, a
delete-record
containing a mark is created and added to the undo tree.