how to unset the foreground color of whitespace-mode for Emacs

2k views Asked by At

In programming files, I use whitespace-mode to highlight the tab and long lines. The default highlighting is too garnish for me.I just want to highlight them with a gray background and keep whatever normal color it should be for the font. How could I set that?

The following setup does not work. I'd like the code beyond 80 columns appearing yellowish, as the characters inside 80 columns in the snapshot.

;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
                    :background "#555"
                    :weight 'bold)

;; face for Tabs
(set-face-attribute 'whitespace-tab nil
                    :background "#555"
                    :weight 'bold)

whitespace-mode

2

There are 2 answers

7
Dmitry On BEST ANSWER

set-face-attribute changes only the attributes you specify.

Set :foreground to nil:

(set-face-attribute 'whitespace-line nil
                    :foreground nil
                    :background "#555"
                    :weight 'bold)
1
Dave Cohen On

For me the unpleasant color turned out to be trailing-whitespace and I'm using this:

;; whitepace looks rediculous in color themes.
(defadvice color-theme-install (after my-color-theme-install-after activate)
  "Fix trailing-whitespace after color theme destroys it"
  (set-face-attribute 'trailing-whitespace nil
                      :foreground 'unspecified
                      :inverse-video 'unspecified
                      :slant 'unspecified
                      :weight 'unspecified
                      :background "#fff"))