Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you 'redo' changes after 'undo' with Emacs?

This article says that "Emacs has redo because you can reverse direction while undoing, thereby undoing the undo".

What does this mean? How can a user 'redo' with Emacs?

like image 741
prosseek Avatar asked Aug 19 '10 23:08

prosseek


People also ask

How do I redo undo in Emacs?

in plain emacs, to redo, just press Ctrl + g first then undo. Further undo will be redo. Press Ctrl + g again to reverse direction.

How do I undo Ctrl Z in Emacs?

Therefore, to re-apply changes you have undone, type 'C-f' or any other command that harmlessly breaks the sequence of undoing; then type 'C-/' to undo the undo command. On the other hand, if you want to resume undoing, without redoing previous undo commands, use 'M-x undo-only' .

What is redo action?

Redo actions that you undidPress CTRL+Y repeatedly until the actions are redone. On the Quick Access Toolbar, click the arrow next to Redo , and then click the actions that you want to redo. The actions are redone in the order in which they are listed. You can only redo the actions in the order in which they occurred.

How do I undo in Emacs Mac?

Emacs records a list of changes made in the buffer text, so you can undo recent changes. This is done using the undo command, which is bound to C-/ (as well as C-x u and C-_ ). Normally, this command undoes the last change, moving point back to where it was before the change.


1 Answers

Short version: by undoing the undo. If you undo, and then do a non-editing command such as C-f, then the next undo will undo the undo, resulting in a redo.

Longer version:

You can think of undo as operating on a stack of operations. If you perform some command (even a navigation command such as C-f) after a sequence of undo operations, all the undos are pushed on to the operation stack. So the next undo undoes the last command. Suppose you do have an operation sequence that looks like this:

  1. Insert "foo"
  2. Insert "bar"
  3. Insert "I love spam"

Now, you undo. It undoes the last action, resulting in the following list:

  1. Insert "foo"
  2. Insert "bar"

If you do something other than undo at this point - say, C-f, the operation stack looks like this:

  1. Insert "foo"
  2. Insert "bar"
  3. Insert "I love spam"
  4. Undo insert "I love spam"

Now, when you undo, the first thing that is undone is the undo. Resulting in your original stack (and document state):

  1. Insert "foo"
  2. Insert "bar"
  3. Insert "I love spam"

If you do a modifying command to break the undo sequence, that command is added after the undo and is thus the first thing to be undone afterwards. Suppose you backspaced over "bar" instead of hitting C-f. Then you would have had

  1. Insert "foo"
  2. Insert "bar"
  3. Insert "I love spam"
  4. Undo insert "I love spam"
  5. Delete "bar"

This adding/re-adding happens ad infinitum. It takes a little getting used to, but it really does give Emacs a highly flexible and powerful undo/redo mechanism.

like image 185
Michael Ekstrand Avatar answered Dec 11 '22 09:12

Michael Ekstrand