16

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?

remvee
  • 561
  • 6
  • 13

2 Answers2

15

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.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
0

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.

ph0t0nix
  • 1,119
  • 13
  • 28