showing trailing whitespace

When writing Makefiles, it's easy to accidentaly have some trailing spaces. This can then lead problems with lines ending in "\", for example:
  SOURCES = foo.c \
will ignore 'bar.c' if there is a space right of the '\'. I've bitten by this a couple of times, and it's not always directly clear that the reason for some linker errors is a superfluous space in the Makefile.

Some other editor makes those spaces/tabs visible; but by default emacs doesn't. However, it's easy to add a Makefile-hook to your .emacs:

(add-hook 'makefile-mode-hook 
    (setq show-trailing-whitespace t)))
This sets the buffer-local variable show-trailing-whitespace, only for Makefiles (including Makefile.am and Makefile.in), and makes those trailing spaces visible.

Some people turn it on for all buffers, but I personally find that quite annoying: usually trailing whitespace does not mean anything.

Note that if you want to see all whitespace/tabs etc., you can use whitespace-mode (in recent emacs versions, use M-x whitespace) - which can be useful at times.

No comments: