git clone 'git://github.com/purcell/whitespace-cleanup-mode.git'
This Emacs library minor mode will intelligently call
before buffers are saved.
whitespace-cleanup is a handy function, but putting it in
before-save-hook for every buffer is overkill, and causes messy diffs
when editing third-party code that did not initially have clean whitespace.
Additionally, whitespace preferences are often project-specific, and
it's inconvenient to set up
before-save-hook in a
whitespace-cleanup-mode is a minor mode which calls
before saving the current buffer, but only if the whitespace in the buffer
was initially clean. It determines this by quickly checking to see if
whitespace-cleanup would have any effect on the buffer.
If you choose not to use one of the convenient
packages in Melpa and Marmalade, you'll need to
add the directory containing
whitespace-cleanup-mode.el to your
whitespace-cleanup-mode in an individual buffer like this:
Optionally enable it everywhere by default using
global-whitespace-cleanup-mode. (You can override that by setting
nil in file or directory local
Alternatively, enable whitespace cleanup for a particular major mode:
(add-hook 'ruby-mode-hook 'whitespace-cleanup-mode)
To enable it for an entire project, set
This mode is built upon some functionality built into
whitespace-action: if you would rather see a warning when saving a file with
bogus whitespace, or even have the save aborted, then set that variable.
Steve Purcell's blog // @sanityinc on Twitter