I have hooked whitespace-cleanup to before-save-hook and there is a timer to auto save buffer every 5 seconds.

When i am typing something, or coding in python, I stop once in a while and buffer will be whitespace cleaned.

So this text

Emacs  is |


Emacs is|


def foo():
     x = 1


def foo():
     x = 1

It is quite annoying to type all that whitespaces again and again. How can i prevent whitespace cleanup at point but still clean whitespace in the remaining buffer?


You can define your own whitespace-cleanup function which does not clean up the current line, e.g.:

(defun white-space-cleanup-without-current-line ()
  (whitespace-cleanup-region (point-min) (line-beginning-position))
  (whitespace-cleanup-region (line-end-position) (point-max)))

and use it for the save hook.

  • Will this work if there are multiple empty lines before and after point? – ChillarAnand Dec 19 '15 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.