0

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 Nov 24 '17 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 Nov 24 '17 at 18:18
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
                        'some-other-mode
                        '...)
    (setq show-trailing-whitespace nil)))

(add-hook 'after-change-major-mode-hook
          'my-hide-trailing-whitespace-maybe)
1

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, privacy policy and cookie policy

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