Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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.


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.)


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.


Wow, that's genius! Thank you for explaining, TIL.


Wow, been using Emacs for decades and didn’t know about „undo in region“. Thanks for sharing!


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.


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.


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


Nice, I will try vundo!


Indeed, undo in regions is the second best feature of emacs undo, wish it were more popular




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: