I have a typing problem in Emacs under WSL. Sometimes it misses my typing ^x as in ^xp and ^xo (prev and next window in my bindings) and I get a stray p or o character in the buffer I want to leave (and I often don't notice it). But it I save all buffers (like I do when typing compile/make), those stray characters can get written out. There is usually just one of them.
So, I want to hack my save-buffer to check if the modification is just one character before saving and ask for comfirmation if it is. Something like:
(defun my-save-buffer ()
(interactive)
(when (or (not (only-one-char-changed))
(y-or-n-p "changed only one character, really save?")
) ; or
(save-buffer)
) ; when
)
The question is how to ask "only-one-char-changed" relatively efficiently? E.g. something I can ask the undo information about.
before-save-hook(once you have the code to check what you want and prompt about it). – Drew Sep 28 '20 at 16:13