Emacs: Make Whitespaces Visible

By Xah Lee. Date: . Last updated: .

whitespace-mode renders {spaces, tabs, newlines} characters with a visible glyph. (in emacs 23 or later)

There is also whitespace-newline-mode and global-whitespace-newline-mode. They only show newline chars.

emacs whitespace mode 2017 02 14
The default rendering of whitespace-mode. Different placement and mix of whitespaces are rendered with different colors. Also, long lines are colored dark purple.

Setting Up whitespace-mode

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://ergoemacs.org/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.

[see ASCII Character Symbols ␀ ␣ ¶]

Whitespace Topic

  1. Clean Empty Lines
  2. Delete Trailing Whitespace
  3. Delete Whitespace around Cursor
  4. Tabs, Space, Indentation Setup
  5. Make Whitespaces Visible
  6. Newline Representation ^M ^J ^L
  7. Batch Convert Line Ending in Dired

Unicode Topic

  1. Unicode Basics
  2. Unicode Tutorial
  3. Emacs File Encoding FAQ
  4. Best Unicode Fonts for Programer
  5. Elisp: Unicode Escape Sequence
  6. Xah Math Input Mode
  7. Xah Unicode Browser Mode

Font Topic

  1. Font Setup
  2. Proportional Font
  3. Cycle Fonts by Command
  4. Set Line Spacing

Rectangle Edit Topic

  1. Edit Column Text, Rectangle Commands
  2. Insert Alphabets A to Z
  3. Copy Rectangle Region to kill-ring
  4. Align Text
  5. picture-mode, ASCII Diagram
  6. Make Whitespaces Visible

Emacs Customization

  1. Emacs init file
  2. What's Major Mode
  3. What's Minor Mode
  4. M-x customize
  5. Organize Init File
  6. Byte Compile Elisp
  7. What's Hook
  8. Avoid Lambda in Hook
  9. Environment Variables in Emacs
  10. Check OS, Version, Host Name
  11. Check Defined/Loaded

packages

  1. Install Packages
  2. Install Package Manually

text editing

  1. Define Keys
  2. Set Mouse Buttons
  3. Tabs, Space, Indentation Setup
  4. auto bracket pair
  5. Copy/Cut Line If No Selection
  6. Isearch space for - _
  7. Ido Completion
  8. Icomplete Completion
  9. Move Cursor by camelCase
  10. Stop Cursor Going into Minibuffer Prompt
  11. Sync Clipboard with Linux X11

file

  1. Default Major Mode
  2. Auto Backup Off
  3. Auto Save
  4. Restore Opened Files
  5. Save Cursor Position
  6. Dired Customization
  7. Open Recently Opened
  8. Open Last Closed File

appearance

  1. Show Line Numbers
  2. Show Cursor Position
  3. Visual Line Mode, Wrap Lines
  4. High Light Current Line
  5. Make Whitespaces Visible
  6. Set Default Window Size
  7. Font Setup
  8. Line Spacing
  9. Set Color Theme
  10. Highlight Paren
  11. Show lambda as λ
  12. Color CSS Hex Code

misc

  1. Default Browser
  2. Misc Init Tips

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc