Emacs Init: Whitespace Mode

By Xah Lee. Date: . Last updated: .

whitespace-mode Config

whitespace-mode by default is ugly. 〔see Emacs: Show Whitespaces

here's how to config it.

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

Download sample test file: whitespace_sample_file.txt

put this in your Emacs Init File:

(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
        '(
          ;; 32 is SPACE, 183 is MIDDLE DOT ·
          (space-mark 32 [183])
          ;; 10 is LINE FEED, 182 isPILCROW SIGN ¶
          (newline-mark 10 [182 10])
          ;; 9 is tab, 182 isPILCROW SIGN ¶
          (tab-mark 9 [9655 9])
          )))

;; 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.

;; char	codepoint (decimal)	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

Emacs, Tab, Indentation, Whitespace