I copy and paste text between lots of different applications. Whitespace mode makes it easy to see all the non printing characters that different apps use to format their notes: Evernote, for example, has a habit of insert non breaking spaces in its notes.
Unfortunately, Doom Emacs uses whitespace mode for tab indents only. In order to restore functionality, I had to read up on whitespace mode. Here are my notes, so you don’t have to do the same.
Whitespace
Whitespace uses two ways to visualize blanks: Faces and Display Tables.
- Faces are used to highlight the background with a color. Whitespace uses font-lock to highlight blank characters. (FontLockMode, rather confusingly, is used for syntax highlighting.)
- Display table changes the way a character is displayed. For example whitespace-mode uses $ by default to show end of lines.
The whitespace-style
variable selects which way blanks are visualized.
whitespace-style
List containing various values. The first is face
which enables visualisation using faces
The following will highlight any part of lines > 80 characters
(setq whitespace-line-column 80) ;; limit line length
(setq whitespace-style '(face lines-tail))
whitespace-display-mappings
Specify an alist of mappings for displaying characters.
Each element has the following form:
(KIND CHAR VECTOR…)
Where:
KIND is the kind of character.
It can be one of the following symbols:
tab-mark for TAB character
space-mark for SPACE or HARD SPACE character
newline-mark for NEWLINE character
CHAR is the character to be mapped.
VECTOR is a vector of characters to be displayed in place of CHAR.
The first display vector that can be displayed is used;
if no display vector for a mapping can be displayed, then
that character is displayed unmodified.
The NEWLINE character is displayed using the face given by
whitespace-newline variable.
(newline-mark ?\n [?\$ ?\n]) ;; Standard emacs $ for EOL
(newline-mark ?\n [182 ?\n]) ;; Unicode for Pilcrow sign
Doom Emacs Config
Doom Emacs uses Whitespace mode for tab indents only. The following restores functionality. (Solution adopted from this post)
(use-package! whitespace
:config
(setq
whitespace-style '(face tabs tab-mark spaces space-mark trailing newline newline-mark)
whitespace-display-mappings '(
(space-mark ?\ [?\u00B7] [?.])
(space-mark ?\xA0 [?\u00A4] [?_])
(newline-mark ?\n [182 ?\n])
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])))
(global-whitespace-mode +1))
Whitespace commands
M-x whitespace-mode
M-x global-whitespace-mode
M-x whitespace-newline-mode
M-x whitespace-toggle-options
M-x whitespace-report Very handy