4 ms·
Construct an Undo Tree from a Linear Undo History
- sleavey 6y agoAh, now I realise why there's no explicit redo command in Emacs. I thought it was just Stallman and friends being weird.
- vlovich123 6y agoHaving read that article as well, I now am even more convinced that my original prediction of not bothering to spend time learning Emacs was correct. The logic of even the undo system is a “big brain” exercise. I’ll admit that VIM has similar problems but at least it’s universality has served me well, whether I’m working on embedded or ssh’ing into a random server.
- ibizaman 6y agoWell, I’m using undo-tree without needing to think about how it works. No big brain involved. It’s just an undo tree and it works great.
- TeMPOraL 6y agoundo-tree is an official Emacs package, but it's not installed by default. You can still stick to standard Emacs undo... ...which arguably is even more confusing, because "undo" and "redo" are the same operation. As long as you keep undoing your changes, it works as everywhere else, but when you stop and do anything else - change something, or even navigate around - all the undos you just did become part of undo history. This means you can now redo them with undo operation - but it also means that, to go further back in undo history, you need to first undo all undos, then undo the changes again, and then continue past the point where you were. Best I can say about this is, it at least doesn't throw away data early. But otherwise it's a super-confusing legacy, which is why undo-tree is one of the first packages I install on a fresh Emacs build. If my description of Emacs built-in undo is confusing, there's actually a better one in undo-tree readme, where the author compares standard undo/redo systems, Emacs undo chain, and undo-tree. If you're curious, see https://elpa.gnu.org/packages/undo-tree.html https://elpa.gnu.org/packages/undo-tree.html, search for "Undo systems". As for understanding undo-tree, I'd say it becomes instantly obvious once you run M-x undo-tree-visualize on your buffer - it renders you the tree in graphical form, and navigating it applies the undos/redos. Emacs has a bunch of such "weird" legacy concepts, but it's a wash really - half of the time, it's something confusing as undo. Other half, it's something much superior to what's used in mainstream editors/IDEs. There's stuff to learn, but then, Emacs is an editor for a lifetime.
- jedimastert 6y agoKinda like turning a tree traversal back into a tree. Neat!
- fctorial 6y agoEmacs source has detailed comments describing it.
- TeMPOraL 6y agoI don't think it describes the same thing this post does (how to create a tree from Emacs' standard linear undo on the fly, in order not to store the actual tree). But both systems - linear and tree - are described extensively in relevant documentation. Standard system is described in Emacs manual - you can access it from Emacs by C-h F undo, or on the web here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Un.... Undo-tree mode has an extensive description of how it works, along with how traditional and Emacs-builtin undo systems work, inside its readme. You can view it from Emacs' package manager, or on the web here: https://elpa.gnu.org/packages/undo-tree.html https://elpa.gnu.org/packages/undo-tree.html, or at the top of undo-tree.el source file (easiest way is to get help on any function/variable from it, and jump to source from help screen).
- fctorial 6y agoRight. Those comments were in the source on undo-tree.
- compressedgas 6y agoThis reminded me of Nelson's OSMIC https://xanadu.com.au/ted/OSMIC/OSMICd1m.html https://xanadu.com.au/ted/OSMIC/OSMICd1m.html
- jmarcher 6y agoEmacs user here. I ind the undo tree neat, but in practice it's a bit finicky sometime unreliable (as in losing history / not being able to undo). I find IntelliJ local history https://www.jetbrains.com/help/idea/local-history.html https://www.jetbrains.com/help/idea/local-history.html , infinitely more reliable and useful. Some time I'll switch to IntelliJ for a second just so it snapshot my project then go back Emacs. The history is preserved between app restarts and over multiple days. It end up being like a parallel to git it some ways. Not replacement for git, but a very nice addition.
- TeMPOraL 6y agoIDEA's Local History looks nice! I'll check it out next time I work with one of JetBrains' IDEs. But on that note, undo-tree can preserve history too! Not sure how reliable it is - I never used it, and some Reddit threads from two years ago suggest there are bugs, but then there was a bunch of undo-tree releases in 2020, so maybe it got fixed. Starting points for further research: undo-tree-auto-save-history (variable), undo-tree-history-directory-alist (variable), undo-tree-save-history (command). Possibly relevant: undo-tree-limit, undo-tree-strong-limit, undo-tree-outer-limit (variables). Personally, I love the visualization (undo-tree-visualize) - but what blew my mind was two accidental discoveries recently. One: t toggles displaying timestamps (how long ago an undo point was applied?), and two: d toggles diffs - a small buffer showing you, in diff format, the changes between current point and previous points in undo history, as you navigate through the tree!