Live data from Hacker News

Text Editor Data Structures: Rethinking Undo

cdacamar.github.io

11–20 of 84 posts

Re: Text Editor Data Structures: Rethinking Undo

#11

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 nee…

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

#12

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 nee…

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

Re: Text Editor Data Structures: Rethinking Undo

#14

I just skimmed it, but it looks like vim really has undo/redo "solved": - Modal editing makes for nice "undo" points, clarifying whether undo should undo "World!" or "!". - "g-" and "g+" eliminate the "orphaned redo". They walk the entire undo/redo tree rather than just the linear undo/redo. - Time travel undo/redo is really handy when you want to go to where you were on the wall-clock. ":earlier 15 minutes" takes yo…

Just to emphasize part of your comment as I think a lot a people aren't fully aware - Vim has an undo tree https://vimhelp.org/usr_32.txt.html#usr_32.txt

Re: Text Editor Data Structures: Rethinking Undo

#15
post #11

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 nee…

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 see…

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

Re: Text Editor Data Structures: Rethinking Undo

#16
Reading the comments on how vim and Emacs have implemented Undo/Redo with various options was very helpful. I personally don't use these editors, but I'm working on a graph drawing tool where the user usually modifies multiple parts of the graph. Right now we only have linear redo/undo implemented. Reading about all this other options is really helpful. Especially the Time travel and the regional undo are very smart features that are also very helpful for all graphic based editors.

Re: Text Editor Data Structures: Rethinking Undo

#17

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 nee…

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

Re: Text Editor Data Structures: Rethinking Undo

#18
I'm surprised there isn't much discussion of data structures here, as that would inform an undo algorithm.

I infer from 'PieceTree'

That this is a binary tree based piece chain.

That makes undo really easy, especially character by character.

Nice explantation of piece chains

https://www.catch22.net/tuts/neatpad/piece-chains/

Re: Text Editor Data Structures: Rethinking Undo

#19

I just skimmed it, but it looks like vim really has undo/redo "solved": - Modal editing makes for nice "undo" points, clarifying whether undo should undo "World!" or "!". - "g-" and "g+" eliminate the "orphaned redo". They walk the entire undo/redo tree rather than just the linear undo/redo. - Time travel undo/redo is really handy when you want to go to where you were on the wall-clock. ":earlier 15 minutes" takes yo…

Far from solved

Modal editing isn't enough if you type whole sentences/paragraphs of text within a single insert session

Also undo in selection is required to "solve" it, as well as semantic points besides "last 15 minutes" (like "last saved session" or "last time you quit the editor")

Also UI with a diff is sometimes better than having to undo/redo to see changes

Re: Text Editor Data Structures: Rethinking Undo

#20
post #12

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 nee…

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.
Post reply on HN