I would like to have whitespace mode turned on for all buffer except for org-mode ones. It is easy to do this when emacs starts up, but since I use a persistant copy of emacs with emacs daemon mode I can't just do it that way.

I tried:

(require 'whitespace)
(setq whitespace-line-column 80)
(setq whitespace-style '(face lines-tail))
(global-whitespace-mode t)
(add-hook 'org-mode-hook
      (lambda ()
          (visual-line-mode 1)
          (auto-fill-mode -1)
          (setq whitespace-style nil)))

but as soon as I visit an org-mode buffer all of my future buffers don't have whitespace mode any more.

I thought of adding a hook to turn whitespace mode on for other major-modes but that seems like a bad way to go since I don't want to enumerate all the other possible modes.

I know that there is whitespace-mode along with global-whitespace-mode, but I'm not sure how I can use that to help here either.

Is there some other way to accomplish this that I'm not thinking of?

  • 3
    You could modify the global-whitespace-mode definition by adding (unless (eq major-mode 'org-mode) . . .). Or, you could enable it on a per major-mode basis instead of globally -- i.e., for each major-mode, use a hook and (whitespace-mode 1). Your idea may also work if you use (setq-local whitespace-style nil), but technically the mode is still active with just the guts / umph taken out.
    – lawlist
    Dec 9, 2014 at 0:45
  • 1
    Unrelated: You should not quote your lambdas
    – Malabarba
    Dec 9, 2014 at 13:48
  • Good point about the quoted lambda. Not sure how or why I ended up with it that way but I removed it from my .emacs Thanks.
    – jcv
    Dec 9, 2014 at 19:23

2 Answers 2

(setq whitespace-global-modes '(not org-mode))

See C-hv whitespace-global-modes RET

  • That works perfect. Thanks. I knew that there had to be something simple that I was missing.
    – jcv
    Dec 9, 2014 at 19:18

It is probably easier to turn off whitespace mode directly, using

 (whitespace-mode -1)

Also, whitespace-style is not a buffer-local variable, so it is modified for all other buffers as well. Try instead

(set (make-local-variable 'whitespace-style) nil)
  • I actually had initially turned whitespace-mode off directly rather than fussing with the whitespace-style var. That was just the current iteration of my attempts. I'm going to try what people suggested and then update this with what worked for me.
    – jcv
    Dec 9, 2014 at 13:28
  • This actually works too, but as you commented yourself, directly turning whitespace mode off rather than dealing with the style is a better solution (which the answer above this does).
    – jcv
    Dec 9, 2014 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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