For most projects I work on I use a before-save-hook to run whitespace-cleanup. This is fine when everybody on the team cleanups up their spaces but sometimes I am involved in already running projects were most files are littered with trailing white. Currently I simply turn off my save-hook and add my share of spaces but ideally I want my diffs to be squeaky clean..

Are there any packages out there which only cleanup whitespace on the lines I touched?

2 Answers 2


The ws-butler package removes whitespace only from the touched lines. The package is available on Melpa.

From that package's README on github:

Only lines touched get trimmed. If the white space at end of buffer is changed, then blank lines at the end of buffer are truncated respecting require-final-newline.

Trimming only happens when saving.

  • Ooh, I like this solution, I've had this same problem often.
    – shapr
    Commented Sep 26, 2014 at 16:32

I recently came across `whitespace-cleanup-mode, which, according to its Github page is

a minor mode which calls whitespace-cleanup before saving the current buffer, but only if the whitespace in the buffer was initially clean.

It may not do exactly what you want, but it may help others with a similar problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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