HACKER Q&A
📣 amichail

Why can't you undo changes after quitting and reloading an app?


Anyone know?


  👤 smallduck Accepted Answer ✓
It would be nice if this was a common OS feature. For some platforms however, system APIs implement the undo stack by way of pointers into runtime objects. A macOS application, for example, has model functions for each kind of document change, and these end with constructing an undo stack item. This contains pointers to the model object and inverse model function, plus captured parameters for that function to perform the undo. (Elegantly, when the inverse functions are called during an undo, the undo stack items they make effectively build a redo stack)

To save this undo stack on this and similar platforms would also require changing the undo mechanism entirely, from using pointers into using static references having meaning across instances of the document model. The inverse model function would have to be identified by an enumeration, the object to change would have to be identified by a kind of search path. The details about saving the data, and where to save it, would be the tiniest part of this problem.

But even on these platforms, if an individual app wishes to implement a custom undo stack which supported this feature, that would be very possible. If cross-platform frameworks implemented support for this that could be a definite advantage over native APIs.


👤 spindle
In most OSes, this would require a tricky decision about where to save the undo data. If you save it in each document (assuming a typical document model), you've got bloat of the documents, and if you save it elsewhere, you've got potential privacy and confidentiality issues (and also still maybe bloat).

There are packages for Emacs that persist undo data. I use one, and love it. I think the above reason is probably the reason they're not included in the base distribution.


👤 hitpointdrew
Because changes aren’t written to disk typically (unless you do a save, or save as). That means the “undos” are stored in memory only. When the application closes everything it had in memory goes with it, only things written to disk (or perhaps a database, depending on the app) will persist between program restarts.