The sgml widget keeps track of changes to the widget contents and records the necessry information to revert these changes. More specifically, the following operations can be reverted:
The sgml widget maintains a list of the most recent operations that have occurred in the widget. When an operation should be undone, the newest entry in this list is examined and the operation that is described by this entry is reverted. After the operation has been undone, the corresponding entry is removed from the undo list and discarded.
where pathname is the name of the sgml widget which should process the pcrmundo command.
This form of the command reverts the last changes made to the content of the sgml widget and removes the corresponding information from the undo list.
If an pcrmundo begin operation (see section
for
details) is in progress (or has just been terminated with an
pcrmundo end command and no other undo-able operations have
occurred since then), all operations belonging to the current
transaction are undone.
Notification commands (see chapter
) will be
invoked during undo operation. For example, if an element is deleted
and later re-inserted by an undo operation, the undo operation will
invoke the insert notification command with a reference to the
re-inserted element.
The widget sets the global variable TkSGML(undo) to the value 1 while it is performing an undo operation; it resets this variable to 0 after the undo operation has been completed. This behaviour can be exploited in notification commands, e.g. to determine if a new element is created or if an element is re-inserted by the pcrmundo command.
Invoking the undo function immediately after these operations should remove the newly inserted character and restore the previous selection and the selected text.
To achieve this effect, the sgml widget allows to combine the undo information for several successive commands into a single undo operation. We use the term transaction (borrowed from database terminology) for a combination of this kind.
A transaction is collection of undo information for an arbitrary number of operations. Each transaction forms single entry in the undo list. Invoking the pcrmundo command reverts all operations that are stored in the transaction.
Transactions are started with the pcrmundo begin command which has the following syntax:
The command takes an optional parameter name that is used to describe the transaction and that will be returned by the pcrmundo type command when the transaction is at the top of the undo list.
After a transaction has been started by the pcrmundo begin command, all operations that occur up to the next pcrmundo end command will be added to the undo transaction. If the pcrmundo command is invoked, all operations in the transcation will be reverted and the transaction will be removed from the undo list.
An undo transaction is terminated by the command pcrmundo end which has the following syntax:
Any undo information that will be added after an pcrmundo end command will again be added directly to the undo list. If no actions have occurred between the pcrmundo begin and pcrmundo end commands, the transaction will be discarded.
Undo transactions ignore the maximum size setting for the undo list; i.e. an undo transaction can contain any number of operations. The transaction itself is counted as a single entry in the undo list.
The following example procedure inserts a new element ename into the sgml widget w. It accepts a list of attriute-value pairs in args and sets each attribute to the corresponding value. The procedures reverts all modifications if any of these steps fails.
The procedure shown above starts an undo transaction before it performs any manipulations of the widget contents. If any errors are encountered by the procedure, it issues an pcrmundo command to revert all changes so far. If no errors occur, the procedure terminates the undo transaction so that a later invocation of the pcrmundo command will remove the newly inserted element.21.1
It is important to notice that the procedure terminates the undo transaction before it reports an error. Failing to terminate the transaction would add all subsequent actions to the still-open undo transaction. If an pcrmundo command is issued later, it would revert all changes that have occured since the invocation of the procedure.
The maximum number of entries in the list can be defined Whenever one of the operations
To undo the last operation that has been performed, the pcrmundo command can be used.
![]() |
Undo functionality is limited to operations that affect the widget contents. Annotation or configuration commands can not be undone. |