News for hackers. Stuff that matters.
Re:Text Editor Data Structures: Rethinking Undo by globular-toast on Monday December 11, 2023 @11:18AM (#38601892)
Emacs undo-tree does everything I need. Emacs also supports undo in region which most editors don't seem to support and wasn't covered by the article.

I actually used regular Emacs undo for years which lets you get everywhere in the tree with a kind of tree traversal but you won't know where you are. I resisted undo-tree for ages but it's definitely worth it as it stays out of the way until the occasion you might need to use it.

Re:Text Editor Data Structures: Rethinking Undo by kleiba on Monday December 11, 2023 @03:20PM (#38604974)
Emacs's undo is great in that invoking an undo command is itself undoable. And that is different from just your standard redo. It definitely needs some getting used to but it is very powerful.

But I think your second points deserves an even bigger mention: Emacs has the ability to apply undo only to a certain "region" - which in Emacs parlance is basically just a selection of text. For those of you who have never seen it: imagine two parts of a file you're editing, say one part at the top, one at the bottom. You start by editing the first part (top) and then then move your cursor somewhere down to the second part of the file (bottom) to do some more editing there. But then you realize that your edits in the first part of the file were baloney. In most other editors, if you wanted to undo them, you'd be forced to also undo the edits in the second part of the file. In Emacs, however, you can simply select the first part at the top of your file - if you hit undo then, it will only undo the last edits done inside that selection and leave all edits outside of that region untouched.

Re:Text Editor Data Structures: Rethinking Undo by bornfreddy on Monday December 11, 2023 @04:01PM (#38605458)
Wow, that's genius! Thank you for explaining, TIL.
Re:Text Editor Data Structures: Rethinking Undo by layer8 on Monday December 11, 2023 @05:17PM (#38606239)
What happens when, for example, you atomically replace “mouse” by “elephant”, then select “epha”, and then region-undo?

The reason most editors don’t implement this is probably that it’s hard to conceive of how it should behave in the general case. (That’s not to say that the way Emacs is implementing it isn’t good and useful.)

Re:Text Editor Data Structures: Rethinking Undo by soamv on Monday December 11, 2023 @07:42PM (#38607612)
Great question. I tried it and I got `elephantmouse`. I was surprised by this, but FWIW I've never encountered this edge case in actual usage.
Re:Text Editor Data Structures: Rethinking Undo by submeta on Monday December 11, 2023 @03:22PM (#38604995)
Wow, been using Emacs for decades and didn’t know about „undo in region“. Thanks for sharing!
Re:Text Editor Data Structures: Rethinking Undo by ska on Monday December 11, 2023 @05:12PM (#38606203)
It's one of those things like rectangle commands; once you know they exist it's hard not to miss them in editors that don't support.
Re:Text Editor Data Structures: Rethinking Undo by matt-attack on Tuesday December 12, 2023 @09:06AM (#38612212)
Emscs undo both both of those reasons is just on another planet than any other editor. Being able to undo your undo (as infinitum) is killer because it just means you can never lose state.

Refional undoing is even more amazing.

Re:Text Editor Data Structures: Rethinking Undo by eviks on Monday December 11, 2023 @04:25PM (#38605712)
Indeed, undo in regions is the second best feature of emacs undo, wish it were more popular
Re:Text Editor Data Structures: Rethinking Undo by rodlette on Tuesday December 12, 2023 @10:49AM (#38613764)
vundo is a simpler implementation: it reuses Emacs's built-in undo/redo and just implements the tree visualisation part.

undo-tree is a reimplementation of Emacs's undo/redo, that supports a tree visualization.

* undo-tree LOC: 4700. https://gitlab.com/tsc25/undo-tree/-/blob/master/undo-tree.e...

* vundo LOC: 1350. https://github.com/casouri/vundo/blob/master/vundo.el

Re:Text Editor Data Structures: Rethinking Undo by globular-toast on Tuesday December 12, 2023 @12:39PM (#38615515)
Nice, I will try vundo!