Search code examples
whitespaceemacs23

Emacs 23.3.1: whitespace style


I've just upgraded to Kubuntu 11.10. After that the way Emacs represents whitespace in whitespace minor mode got changed. It were shaded rectangulars and not Emacs puts dots in the place of white space:

enter image description here

I tried to change it through the M-x customize-group and then whitespace -- but there's no such thing as a dot. It says that whitespaces are represented by shading (see the pic above) - but they are not (see the same pic).

Here's the value of Whitespace Space face:

enter image description here

I also asked this question at superuser but since I got 0 replies there -- I decided to consult another community.

Edit 1:

Following the Luke's solution gives no coloring to space nor to tabs (unless I've done something wrong):

enter image description here

Edit 2:

Adding face here fixes Luke's solution. Thanks to Sergey.

(setq whitespace-style (quote
   ( face spaces tabs newline space-mark tab-mark newline-mark)))

Edit 3:

Currently I'm using:

(custom-set-variables
 '(whitespace-line-column 9999999)
 '(whitespace-tab-width 4 t)
 '(whitespace-display-mappings '(
    (space-mark ?\ [?\u00B7] [?.])                 ; space - centered dot
    (space-mark ?\xA0 [?\u00A4] [?_])            ; hard space - currency
    (newline-mark ?\n [?$ ?\n])                      ; eol - dollar sign
    (tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])       ; tab - left quote mark
                               ))
 '(whitespace-style '(face spaces tabs newline space-mark tab-mark newline-mark))
 )

(custom-set-faces 
 '(default ((t (:inherit nil :stipple nil :background "#ffffb1" :foreground "#141312" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 125 :width normal :foundry "monotype" :family "DejaVu Sans Mono"))))
 '(whitespace-trailing ((t (:background "grey99"))))
)

at Emacs 24.3.50.1


Solution

  • There's probably a better way to do this, but adding this to your .emacs should work:

    (setq whitespace-display-mappings
          '(
        (space-mark   ?\     [? ]) ;; use space not dot
        (space-mark   ?\xA0  [?\u00A4]     [?_])
        (space-mark   ?\x8A0 [?\x8A4]      [?_])
        (space-mark   ?\x920 [?\x924]      [?_])
        (space-mark   ?\xE20 [?\xE24]      [?_])
        (space-mark   ?\xF20 [?\xF24]      [?_])
        (newline-mark ?\n    [?$ ?\n])
        (tab-mark     ?\t    [?\u00BB ?\t] [?\\ ?\t])))
    
    (custom-set-faces
     '(whitespace-space
       ((((class color) (background dark)) (:background "red" :foreground "white"))
        (((class color) (background light)) (:background "yellow" :foreground "black"))
        (t (:inverse-video t)))))
    

    The standard value of whitespace-display-mappings uses a 'middle dot' for a space, the code above uses a standard space. You can change the colours for whitespace-space as required.