I’m an Emacs newbie (using Doom Emacs with GNU Emacs 29.1). I came from vim, and battling with undo there was crazy enough, but I won using this:

inoremap  u
inoremap  u
inoremap  u
inoremap  u
inoremap  u
inoremap  u
inoremap  u
inoremap , ,u
inoremap . .u
inoremap ( (u
inoremap [ [u
inoremap = =u
inoremap \" \"u
inoremap  u
inoremap  u

Also, I had autogroup that breaks undo every 4 seconds.

Basically, this configuration breaks undo on almost every possible type command, every Spacebar, Enter, comma, bracket, moving up, down, everything. This is because I hate when undo deletes the whole screen of text.

How do I replicate this in Emacs? I read this, but it doesn’t say what is considered a “recent change”.

  • orzechod@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    the paragraph here gives some useful details: https://www.gnu.org/software/emacs/manual/html_node/elisp/Undo.html#index-undo_002dauto_002damalgamate

    The editor command loop automatically calls undo-boundary just before executing each key sequence, so that each undo normally undoes the effects of one command. A few exceptional commands are amalgamating: these commands generally cause small changes to buffers, so with these a boundary is inserted only every 20th command, allowing the changes to be undone as a group. By default, the commands self-insert-command, which produces self-inserting input characters (see User-Level Insertion Commands), and delete-char, which deletes characters (see Deleting Text), are amalgamating.

    this means emacs will group together a certain number of inserted characters into an atomic unit; it’s that unit which is undone by the undo command. if you want character-by-character undo then you will need to tell emacs to not perform this grouping. one thing to try would be to add advice to the insert-char function to set that undo boundary for you upon each keystroke; I’m sure there are other ways to do this as well.

    • Gandalf_the_Gray@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      The following paragraph from what you quote has the heavy handed approach whereby no changes are amalgamated and undo would work character by character.

      The maximum number of changes that can be amalgamated is controlled by the amalgamating-undo-limit variable. If this variable is 1, no changes are amalgamated.