I want to see all spaces at the beginning of a line as dots. Also tabs and line breaks. So I've set my init.el file as the following:

(setq-default indent-tabs-mode nil)

(setq whitespace-style '(space-mark newline-mark tab-mark))

(whitespace-mode t)

(add-hook 'before-save-hook 'whitespace-cleanup)

(add-hook 'prog-mode-hook
  (lambda ()
    (whitespace-mode t)))

(add-hook 'text-mode-hook
  (lambda ()
    (whitespace-mode t)))

(setq whitespace-display-mappings
  '((newline-mark 10 [172 10])
   (space-mark 32 [183] [46])))

And that's the result:

Emacs result

You can see the desired effect for the line breaks and the dots here, but the dots are everywhere (Eg. between the words class and Lottery). I want only the leading spaces, actually to mark my indentation. How can I do that?

Also, how can I format the colors? I want to select a darker dot and line break. I know it's using a display table so faces won't work, right?

  • 3
    For your first question: You can customize whitespace-space-regexp to only highlight leading spaces. See C-h v whitespace-space-regexp (or M-x describe-variable ...). The docs for whitespace-space-regexp contain an example of how to only highlight leading spaces.
    – Arnot
    Oct 9, 2017 at 9:47
  • If you wish to use whitespace-mode, but do not want to visualize ALL spaces, then comment out space-mark in the whitespace-style setting. The doc-string for the whitespace-style variable contains an entry for space-mark that states: "SPACEs and HARD SPACEs are visualized via display table."
    – lawlist
    Mar 21, 2020 at 22:51
  • Closing so we can merge with a new/nearly identical question.
    – Dan
    Mar 25, 2020 at 12:21


Browse other questions tagged or ask your own question.