enter image description here

I have set show-trailing-whitespace as default in my .emacs file but I don't want it to work on shell and some specific buffer. I can disable it manually every time I open an emacs shell but I want more of a permanent solution. How can I do that?

  • Possible duplicate of How to disable global Linum mode for certain mode?
    – Drew
    Commented Nov 24, 2017 at 18:12
  • Well, it's not exactly a dup, since this is about a variable and not a mode. But it's very similar. It would be good to have a single Community Q&A that covers the general idea (i.e., covers both variables and modes).
    – Drew
    Commented Nov 24, 2017 at 18:18

2 Answers 2


Chances are that you'll want to do this for numerous modes, so I would suggest using an approach which makes that simpler to specify. e.g.:

(defun my-hide-trailing-whitespace-maybe ()
  "Disable `show-trailing-whitespace' in selected modes."
  (when (derived-mode-p 'shell-mode
    (setq show-trailing-whitespace nil)))

(add-hook 'after-change-major-mode-hook

Put the following line in your init-file:

 (add-hook 'shell-mode-hook (lambda ()
                             (setq show-trailing-whitespace nil)))

That disables show-trailing-whitespace locally in shell buffers. Change shell-mode-hook to any major mode hook you want if you like to disable show-trailing-whitespace also in other modes.

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.