I'm using global-whitespace-mode with a particular whitespace-style as a default for all modes. How can I disable whitespace-mode completely for a single mode, eg. incoming email?

I tried the following, but I still get all the default whitespace styles when looking at incoming email.

(setq whitespace-style '(face trailing lines tabs big-indent))
(add-hook 'rmail-mode-hook '(whitespace-mode 0))
  • stackoverflow.com/q/6837511 might also prove informative. – phils Mar 26 '18 at 12:15
  • @phils: Very interesting! How do I enable this? (setq whitespace-global-modes '(prog-mode)) did't work. – forthrin Mar 26 '18 at 13:03
  • It's not using derived-mode-p so you can't use prog-mode here (unless you are actually editing a buffer with major mode prog-mode, which in practice you wouldn't ever do). You have to list individual major modes. But surely (based on your question) you want to use the syntax shown in that duplicate: '(not rmail-mode) – phils Mar 26 '18 at 13:19
  • I see. Then, I agree! – forthrin Mar 26 '18 at 13:45

You can do like that:

(define-global-minor-mode my-global-whitespace-mode whitespace-mode
  (lambda ()
    (unless (derived-mode-p 'rmail-mode 'term-mode)
(my-global-whitespace-mode 1)

Or activate only for prog-mode

(define-global-minor-mode my-global-whitespace-mode whitespace-mode
  (lambda ()
    (when (derived-mode-p 'prog-mode)
(my-global-whitespace-mode 1)
  • I forgot to mention that I'm highlighting not just trailing whitespace, but several other types of whitespace as well. show-trailing-whitespace onlys affect trailing whitespace at the end of lines, doesn't it? Whereas I wish to get rid of all whitespace highlighting for incoming email. Updated my original post. Sorry about that. How does that affect your suggestion? – forthrin Mar 23 '18 at 16:37
  • So you can use the first proposition. – djangoliv Mar 26 '18 at 7:29
  • You have to define a new mode to disable whitespace-mode for particular modes? It's not possible with a one-liner? – forthrin Mar 26 '18 at 8:30
  • Yes, I don't think so: stackoverflow.com/questions/6837511/… – djangoliv Mar 26 '18 at 8:50
  • I want whitespace-mode where it makes sense, i.e.. all programming languages and shell scripts, and off for everything else (email, dired, plain text, etc.) Can Emacs distinguish "code modes" from all else so this can be automated? – forthrin Mar 26 '18 at 9:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.