[Gazpacho] Emacs and trailing whitespace

Pádraig Brady P at draigBrady.com
Mon Jan 16 10:54:03 CET 2006


Johan Dahlin wrote:

> Hi fellow hackers
>
> I just committed a quite big patch to remove trailing whitespace in
> all python files.
> It's kinda annoying, since they tend to show up in patches.
>
> In emacs, if you add this to your .emacs you'll see a big red block in
> all places where there
> are trailing whitespaces:
>
> (mapc (lambda (hook)
>      (add-hook hook (lambda ()
>           (setq show-trailing-whitespace t))))
>      '(python-mode-hook))
>
> To remove all whitespace in a buffer, just type M-x
> delete-trailing-whitespace
>
> Could all emacs users please add this so we can keep them from
> creeping in again?


And vim users can put the following in ~/.vimrc

"flag problematic whitespace (trailing and spaces before tabs)
"Note you get the same by doing let c_space_errors=1 but
"this rule really applys to everything.
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/
"use :set list! to toggle visible whitespace on/off
set listchars=tab:>-,trail:.,extends:>

To remove all trailing whitespace in a buffer:

:%s/\s\+$//

I also noticed the following to automatically do this,
but I've not tested it:

" automatically delete trailing whitespace
autocmd BufRead * silent! %s/\s\+$//
autocmd BufEnter *.py :%s/\s\+$//e


For reference here are my vim settings:
http://www.pixelbeat.org/settings/.vimrc

Pádraig.


More information about the Gazpacho mailing list