How to make M-x undo more fine-grained or sensitive?

Example: say, I wrote:

foo (bar baz) ()

then I M-x undo and receive:

foo (bar

but what I want to get after this undo is:

foo (bar baz)

  • 1
    You can restrict undoing by marking the appropriate part of the buffer before calling undo. – DoMiNeLa10 Jan 22 at 21:22
  • I'm not sure that what you want is readily possible. Here's a good write up of how the Emacs undo command works: web.archive.org/web/20180518040652/https://www.reddit.com/r/… Also, be wary of undo-tree. It has a bug in it which loses the history (quite frequently in my experience): github.com/emacs-evil/evil/issues/1074 – Lorem Ipsum Jan 22 at 22:24
  • See the emacs documentation for undo. It states that "Consecutive character insertion commands are usually grouped together into a single undo record, to make undoing less tedious." So the behavior depends on what you typed. If you typed baz) () all consecutively, then those would be grouped together and all undone at once. The manual doesn't indicate any way to change that, although perhaps there are packages that will help (I don't know). – MTS Jan 22 at 22:24
  • I guess my question is: why do you expect to get foo (bar baz)? What is the sequence of actions you've taken prior to issuing the undo command? – MTS Jan 22 at 22:53
  • 1
    @MTS expect -> want – jue Jan 23 at 21:26

I like to do two things with undo. I turn off the amalgamation stuff (which by doing so permits undo one keystroke at at time); and, I get rid of the timer (because timers affect performance and drive me absolutely bonkers, unless they are idle-timers.

Alternatively, you can modify undo-auto-amalgamate which is hard coded at 20 and set it to a lesser/greater amount.

(when (timerp undo-auto-current-boundary-timer)
  (cancel-timer undo-auto-current-boundary-timer))

(fset 'undo-auto--undoable-change
      (lambda () (add-to-list 'undo-auto--undoably-changed-buffers (current-buffer))))

(fset 'undo-auto-amalgamate 'ignore)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.