This page tells you how to setup emacs's whitespace-mode (in emacs 23 or later), and how to use it.
whitespace-mode renders {spaces, tabs, newlines} characters with a visible glyph. This feature is useful for working with “tab separated values” (TSV) that's commonly used format for importing/exporting address books or spreadsheets. It's also useful in whitespace-significant languages such as Python.
To use it, call whitespace-mode. The command will toggle it on and off, for current file. Call global-whitespace-mode to toggle it globally for current emacs session.
There is also whitespace-newline-mode and global-whitespace-newline-mode. They only show newline chars.
whitespace-mode.
Different placement and mix of whitespaces are rendered with different colors. Also, long lines are colored dark purple. (download whitespace_sample_file.txt)
whitespace-mode.How to reduce colors in whitespace-mode?
Put the following in your emacs init file:
;; make whitespace-mode use just basic coloring (setq whitespace-style (quote (spaces tabs newline space-mark tab-mark newline-mark)))
How to make whitespace-mode use the pilcrow sign “¶” for newline instead of the dollar sign?
Put the following in your emacs init file:
(setq whitespace-display-mappings
;; all numbers are Unicode codepoint in decimal. ⁖ (insert-char 182 1)
'(
(space-mark 32 [183] [46]) ; 32 SPACE 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
(newline-mark 10 [182 10]) ; 10 LINE FEED
(tab-mark 9 [9655 9] [92 9]) ; 9 TAB, 9655 WHITE RIGHT-POINTING TRIANGLE 「▷」
))
In the above, the numbers are Unicode char code in decimal. Depending on your choice of font, some glyphs may not show up or correctly. If so, you can try the following glyphs.
| Glyph | Unicode Code Point (Decimal) | Unicode Name |
|---|---|---|
| · | 183 | MIDDLE DOT |
| ¶ | 182 | PILCROW SIGN |
| ↵ | 8629 | DOWNWARDS ARROW WITH CORNER LEFTWARDS |
| ↩ | 8617 | LEFTWARDS ARROW WITH HOOK |
| ⏎ | 9166 | RETURN SYMBOL |
| ▷ | 9655 | WHITE RIGHT POINTING TRIANGLE |
| ▶ | 9654 | BLACK RIGHT-POINTING TRIANGLE |
| → | 8594 | RIGHTWARDS ARROW |
| ↦ | 8614 | RIGHTWARDS ARROW FROM BAR |
| ⇥ | 8677 | RIGHTWARDS ARROW TO BAR |
| ⇨ | 8680 | RIGHTWARDS WHITE ARROW |
See also: Best Unicode Fonts for Programing ◇ Computing Symbols in Unicode.
How to delete trailing whitespaces?
Call delete-trailing-whitespace. For more on whitespace manipulation, see: Emacs: Tabs, Space, Indentation Setup