Emacs Init: Whitespace Mode

By Xah Lee. Date: .

whitespace-mode Config

You can setup whitespace-mode to use a simple color scheme.

emacs whitespace mode clean 2017 02 14
A clean setup for whitespace-mode.

Download sample test file: whitespace_sample_file.txt

For a simple and clean whitespace mode setup, put the following in your emacs init.

(progn
 ;; Make whitespace-mode with very basic background coloring for whitespaces.
  ;; http://xahlee.info/emacs/emacs/whitespace-mode.html
  (setq whitespace-style (quote (face spaces tabs newline space-mark tab-mark newline-mark )))

  ;; Make whitespace-mode and whitespace-newline-mode use “¶” for end of line char and “▷” for tab.
  (setq whitespace-display-mappings
        ;; all numbers are unicode codepoint in decimal. e.g. (insert-char 182 1)
        '(
          (space-mark 32 [183] [46]) ; SPACE 32 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
          (newline-mark 10 [182 10]) ; LINE FEED,
          (tab-mark 9 [9655 9] [92 9]) ; tab
          )))

In the above, the numbers are Unicode codepoint in decimal. Depending on your choice of font, some glyphs may not show up or correctly. If so, you can try the following glyphs.

charcodepoint (decimal)name
·183MIDDLE DOT
182PILCROW SIGN
8629DOWNWARDS ARROW WITH CORNER LEFTWARDS
8617LEFTWARDS ARROW WITH HOOK
9166RETURN SYMBOL
9655WHITE RIGHT POINTING TRIANGLE
9654BLACK RIGHT-POINTING TRIANGLE
8594RIGHTWARDS ARROW
8614RIGHTWARDS ARROW FROM BAR
8677RIGHTWARDS ARROW TO BAR
8680RIGHTWARDS WHITE ARROW

[see ASCII Character Symbols ␀ ␣ ¶]

Emacs Whitespace Mode