3

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 |

becomes

Emacs is|

and

def foo():
     x = 1
     |

becomes

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?

2

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 ()
  (interactive)
  (whitespace-cleanup-region (point-min) (line-beginning-position))
  (whitespace-cleanup-region (line-end-position) (point-max)))

and use it for the save hook.

|improve this answer|||||
  • 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.