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”.

  • db48x@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 months ago

    Good, because that is very bad advice. orzechod already gave you a link to the manual, but the upshot is that basically every emacs command already breaks the undo into segments. Arrow keys invoke commands to move the cursor around, and backspace and return invoke commands as well, so you don’t need to add anything to your config to get most of what you want.

    The only difference is that the default Emacs config groups up inserted characters into segments of 20 characters, instead of splitting them on punctuation and spaces. Getting that last bit is harder, so you might actually prefer to live with it. You should be able to do it with advice on self-insert-command, but I would have to do a little research and try it out before I would be confident in my answer. (I am 90% sure that you can set a variable to control whether the current command should be amalgamated or not, but it’s been years since I last looked at how undo is implemented.)

    I should also point out that brackets might or might not be amalgamated depending on other choices you might have made. For example, if you use a minor mode that automatically inserts the closing bracket when you type the opener, then it won’t be amalgamated because that is invoking a command rather than merely inserting a character.

    • chesheersmile@fediverser.communick.devOPB
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

      Advising self-insert-command may be a way. But with my zero knowledge of elisp I have absolutely no idea how to do that. All my attempts have failed.

      So for now this kinda adds to my long list of “Not solved in any reasonable way”.