1

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.

(global-whitespace-mode)
(setq whitespace-style '(face trailing lines tabs big-indent))
(add-hook 'rmail-mode-hook '(whitespace-mode 0))
forthrin
  • 451
  • 2
  • 10
  • https://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

1 Answers1

3

You can do like that:

(define-global-minor-mode my-global-whitespace-mode whitespace-mode
  (lambda ()
    (unless (derived-mode-p 'rmail-mode 'term-mode)
      (whitespace-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)
      (whitespace-mode))))
(my-global-whitespace-mode 1)
Jack Kelly
  • 135
  • 6
djangoliv
  • 3,169
  • 16
  • 31
  • 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 07: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 08:30
  • Yes, I don't think so: https://stackoverflow.com/questions/6837511/automatically-disable-a-global-minor-mode-for-a-specific-major-mode – djangoliv Mar 26 '18 at 08: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 09:02
  • with prog-mode. See edit – djangoliv Mar 26 '18 at 11:52