Is it possible to wrap an arbitrary series of operations such that when a single undo command is issued, all of the wrapped operations are undone at once, rather than requiring multiple undos to undo them?
For example, let's say I delete a line, move up two lines, delete another line, move up two more lines, and delete one more line. I'd like to be able to wrap those all those operations somehow so that when a single undo command is issued, all three deleted lines are restored to their proper locations.
Of course, this is just an example, and I'd like to be able to do that for any sequence of operations.
Update: I found an answer here involving
with-undo-collapse which worked.
Update 2: The answer linked to above seems to be buggy, and while it does allow me to undo multiple operations in one undo, it sometimes undoes even more than what was wrapped in
with-undo-collapse. I'm going to have to try to debug that code to figure out what's going wrong.
Update 3: The buggy code for
with-undo-collapse and associated functions from the answer above is impenetrable to me, and I've failed at debugging it. As such, I'm forced to abandon it, as I'd rather have too-granular an undo rather than not-granular-enough. I'll now see if I can further explore Emacs' undo system on my own, using the links and tips provided elsewhere in this thread and maybe come up with my own, working solution.
Update 4: It looks like the simplest and the most bulletproof answer is to just wrap the block in