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?– DrewCommented 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).– DrewCommented Nov 24, 2017 at 18:18
Add a comment
|
2 Answers
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)
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.