![]() |
Undo: pitfalls and known problems | ![]() |
The statements marked (checked) were verified on 2026-10-06 by scripts which simulate user actions with start-editing and end-editing in a headless TeXmacs.
Clearing the history acts on all buffers and marks them as modified (checked, issue #301 of mgubi/texmacs). Tools\(\rightarrow\)Miscellaneous\(\rightarrow\)Clear undo history calls clear-undo-history, which calls global_clear_history (
archiver.cpp:85
) instead of clearing the archiver of the current editor. clear also sets last_save to -1, so every open buffer, including saved ones, loses its history and is then reported as modified.
An unknown marker loses the history, or the document (checked, issue #301). If mark_end does not find its marker, remove_marker prints warning, marker not found and replaces the whole history by an empty one (
archiver.cpp:587
); if the marker lies below a future, it prints warning, cannot remove marker and drops the marker and everything below it. mark_cancel is worse: looking for the marker, it undoes and forgets the editor's own steps one by one, so with an unknown marker it reverts the document through all of the user's changes down to a step of another author or to the beginning; a document with three steps typed by the user became empty, without any warning, and lost its history. This replaced a fatal error (bug #60743 of the old tracker); it happens when a mark-start and its mark-end are executed in different editors, or when the history was changed in between. With ADVANCED_DEVELOPER_MODE the second case is still an assertion.
Typing is undone in large pieces (checked). simplify joins any two consecutive insertions into the same string at adjacent positions, without a time limit, so text typed without moving the cursor, even over several minutes, is undone at once. Only a change of string (a new paragraph, a formula), typing at another position, a deletion or a save starts a new step.
The history belongs to a view. The archiver is a member of the editor, so a buffer shown in two windows has two histories, in which the changes made in the other window belong to another author; and the history is lost when the view is deleted. Changes to a buffer without a view are not recorded at all (see the FIXME in
edit_modify.cpp:145
).
Undo is silent while changes are pending. undo and redo of the archiver do nothing while current is not empty (the editor first drops the pending cursor modifications). A Scheme function which modifies the document and then calls (undo 0) in the same action first has to close the step with (add-undo-mark).
Undo inside graphics. While a graphical operation is in progress (graphics-undo-enabled is false), undo only resets the state of the graphics editor.
The modified state is approximate. It compares numbers of steps (depth and last_save). Operations which reorder steps (expose, normalize) or forget them set last_save to -1, so after undoing one's own change past the output of a plug-in the document counts as modified even if it is back in its saved state. Conversely, mark_end merges the steps after a marker into one (compress) but decreases depth only by one, so after a group of several steps the depth is too high and undoing back to the saved state is not recognized.
Swapped patches may be paired with the wrong inverse (issue #144 of mgubi/texmacs). swap on two modification patches swaps the forward modifications and the inverses separately (
patch.cpp:488
); when an insertion lands where a removal happened, the two swaps can break the tie differently, and possible_inverse only compares kinds and lengths, so it accepts the result. Undoing the whole sequence still restores the tree, but undoing one step does not. The archiver swaps patches in split and expose, so a single undo in a history with several authors may give a wrong document. A fix is proposed in pull request #153.
is_applicable crashed on a join below a string (issue #144). can_join (
modification.cpp:196
) takes the length of a string for a number of children and then indexes the string. Fixed by pull request #152 in wip_fixes.
Plug-in output and undo (checked). The output of an evaluation can only be undone together with, or after, the step which sent the input, since a patch is never moved past the birth of its author. Undoing that step therefore also removes the output.