When you enter the command C-/, Emacs undoes some part of your recent changes to a buffer. When you enter C-/ again, it undoes another chunk of work.
I have read the Emacs manual entry on Undo but it is vague about exactly how it works. The manual says “Consecutive character insertion commands are usually grouped together into a single undo record” but it does not explain how it decides the number of character insertion commands that constitute a group. The number of characters it puts in a group seems random.
Can anyone explain the algorithm Emacs uses to group characters into undo records?
The logic for setting undo boundaries is mostly in
self-insert-commandwhich is implemented incmds.c. You’ll have to read the code for the full story, but basically:internal_self_insert) cause an an undo boundary to be added immediately, and the character count to be reset. Reading the code, it looks as though these are: (1) inoverwrite-mode, if you overwrote a character with one that has a different width, e.g. typing over a tab; (2) if the character you inserted caused an abbreviation to be expanded; (3) if the character you typed causedauto-fill-modeto insert indentation.undo-boundary. This does not cause the character count to be reset.