2009-08-15

How to use and setup Emacs's whitespace-mode

perm url with update: http://xahlee.org/emacs/whitespace-mode.html.

How to use and setup Emacs's whitespace-mode

Xah Lee, 2009-08-14

This pages tells you how to setup emacs's whitespace-mode, and how to use it.

Emacs 23 has this whitespace-mode feature. It renders spaces, tabs, newlines characters with a visible glyph.

This feature is useful for working with “tab separated values” (CSV) that's a common format for importing/exporting address books or spreadsheets. It's also important in whitespace-significant langs such as Python.

Type “Alt+x whitespace-mode” to toggle it on and off. Type “Alt+x global-whitespace-mode” to toggle it globally. There is also whitespace-newline-mode and global-whitespace-newline-mode. They only show newline chars.

emacs whitespace

The default rendering of whitespace-mode, pretty unreadable. Different placement and mix of whitespaces are rendered with different colors. Also, long lines are colored dark purple. (download whitespace_sample_file.txt)

How to clean whitespaces in one shot?

Select a region then type “Alt+x whitespace-cleanup”, which will delete spaces or tabs in a smart way. (call describe-function to see detail.)

You can also use delete-trailing-whitespace, delete-whitespace-rectangle. Both works on a region.

For more fine control of deleting whitespaces, you can use use query-replace, query-replace-regexp, to replace whitespaces.

How to insert Tab or Newline char?

To insert a literal tab char, press “Ctrl+q Tab”. To type a newline char, type “Ctrl+q Ctrl+j”.

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”:

(setq whitespace-display-mappings
 '(
   (space-mark 32 [183] [46]) ; normal space
   (space-mark 160 [164] [95])
   (space-mark 2208 [2212] [95])
   (space-mark 2336 [2340] [95])
   (space-mark 3616 [3620] [95])
   (space-mark 3872 [3876] [95])
   (newline-mark 10 [182 10]) ; newlne
   (tab-mark 9 [9655 9] [92 9]) ; tab
))

In the above, the numbers are unicode points. Depending on your choice of font, some glyph may not show up with your font. You may explore with the following unicode chars.

  • “·”, MIDDLE DOT, 183
  • “¶”, PILCROW SIGN, 182
  • “↵”, DOWNWARDS ARROW WITH CORNER LEFTWARDS, 8629
  • “▷”, WHITE RIGHT POINTING TRIANGLE, 9655
  • “▶”, BLACK RIGHT-POINTING TRIANGLE, 9654
  • “→”, RIGHTWARDS ARROW, 8594
  • “↦”, RIGHTWARDS ARROW FROM BAR, 8614
  • “⇥”, RIGHTWARDS ARROW TO BAR, 8677
emacs whitespace clean

A clean setup for whitespace-mode. Spaces are displayed by “·” (MIDDLE DOT; unicode 183), Tabs are displayed by “▷” (WHITE RIGHT POINTING TRIANGLE; unicode 9655), Newline are displayed as “¶” (PILCROW SIGN; unicode 182). Distinction of various mix of types of whitespaces are removed.

2009-08-13

A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

perm url with updates: http://xahlee.org/UnixResource_dir/writ/emacs_whitespace-mode_problems.html

A Exhibition Of Tech Geekers Incompetence: Emacs whitespace-mode

Xah Lee, 2009-08-13

Just wanted to express some frustration with whitespace-mode.

Emacs 23, just released, has this whitespace-mode feature. It renders spaces, tabs, newlines characters with a visible glyph. This feature, is in Microsoft Word since about 1992.

This feature is important in practical ways. For example, when you work with “tab separated line” files (CVS) that's a common format for importing/exporting address books or spreadsheets. It's also important in whitespace-significant langs such as Python. Or, in text processing when placement of space and tabs matters in the output.

All i wanted, is to make Space and Tab and Newline chars visible.

However, the emacs whitespace-mode does much more than that. It is designed for tech geeking control freaks to tune every aspect of white space in his source code. The mode is filled with bells and whistles. It distinguishes tabs mixed with spaces, EOLs mixed with spaces, EOLs at beginning of file, EOLs at end of file, run on spaces at end of line, lines that has nothing to do with white spaces but is simply longer than 80 chars, etc. Each of these is rendered with different foreground, background, colors, so that they cannot possibly escape the notices of control freaks.

By default, most of these are on, so that, when you turn on the mode, most reasonable clean source code become this colorful rainbow unreadable fuck.

I tried to tune it, with my 10 years of emacs of fucking 16 hours of using per day, and 3 years of elisp coding experience. But, after a hour, it's confusion hell sans avail.

O, that Alex idiot with his emacswiki, refused to lead emacswiki into any readable state. All he can think about is my social skills. (See: Problems of Emacswiki.)

What the fuck motherfuck. Hi tech geekers, coding freaks, social science ignoramus fucks, basic economics illiterate FSF fucks, freedom abusing selfish ideologists fucks, Richard Stallman propagandist fuck, we-try-to-be-easy-to-use linuxer idioting fucks, FUCK U.


Related essays: