1

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.

Drew
  • 77,472
  • 10
  • 114
  • 243
intel_chris
  • 329
  • 2
  • 12
  • Put your code on before-save-hook (once you have the code to check what you want and prompt about it). – Drew Sep 28 '20 at 16:13
  • Please do not post the same question to both StackOverflow and SE.emacs. Please choose one to keep and delete the other. Thx. – Drew Sep 28 '20 at 16:17
  • Sorry, had forgotten about this site when I posted the first copy. – intel_chris Sep 28 '20 at 19:09

0 Answers0