5

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)

jue
  • 4,476
  • 8
  • 20
  • 1
    You can restrict undoing by marking the appropriate part of the buffer before calling `undo`. –  Jan 22 '19 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: https://web.archive.org/web/20180518040652/https://www.reddit.com/r/emacs/comments/6yzwic/how_emacs_undo_works/ Also, be wary of `undo-tree`. It has a bug in it which loses the history (quite frequently in my experience): https://github.com/emacs-evil/evil/issues/1074 – Lorem Ipsum Jan 22 '19 at 22:24
  • See the emacs [documentation for undo](https://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html). 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 '19 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 '19 at 22:53
  • @DoMiNeLa10 interesting, thanks for this tip! – jue Jan 23 '19 at 21:04
  • @MTS because I don't like the behaviour and it's emacs what I'm using :) – jue Jan 23 '19 at 21:06
  • I think you misunderstood me. I was trying to ask you to describe exactly what happened before you used `undo`. According to the documentation, if you sequentially typed the sequence of characters `f o o ( b a r b a z ) ( )` and then issued the `undo` command, it should remove the entire thing. So I was asking what made you expect that only the final two parens would be removed. Perhaps when you said "what I expect after this undo" you really meant "what I want after this undo"? Anyway, disabling amalgamation as suggested in the accepted answer is probably your best bet. – MTS Jan 23 '19 at 21:21
  • 1
    @MTS expect -> want – jue Jan 23 '19 at 21:26

1 Answers1

7

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)
lawlist
  • 18,826
  • 5
  • 37
  • 118