How to enable whitespace mode for certain modes only

I am trying to activate emacs whitespace-mode automatically only in certain modes. According to the documentation, enabling global-whitespace-mode and setting the whitespace-global-modes variable should do just that. But I can not get it to work correctly.

In my .emacs.el I have:

 (require 'whitespace) (global-whitespace-mode t) (setq whitespace-global-modes '(c-mode c++-mode)) 

but the definition of whitespace-global-modes seems to be ignored; global-whitespace-mode activated in each buffer. I know that I have the variable name correctly, because Ch v whitespace-global-modes tells me:

 whitespace-global-modes value is (c-mode c++mode) Documentation: Modes for which global `whitespace-mode' is automagically turned on. ... 

So what am I doing wrong? Am I misunderstood the purpose of whitespace-global-modes ?

I am running emacs 23.2.1.

+6
source share
2 answers

It turns out that the commands in my .emacs.el were (almost) working after all. I was confused by the fact that "WS" appears in the simulation of all buffers, although only the C and C ++ buffers received, if desired, the effect of whitespace-mode .

Another problem was that I had a typo: c++mode and not c++-mode .

+3
source

Apparently, the meaning of whitespace-global-modes is very different from what you understand (and me).

How about trying

 (require 'whitespace) (add-hook 'c-mode-hook (function (lambda () (whitespace-mode t)))) 

and repeat the same for C ++ mode?

+5
source

Source: https://habr.com/ru/post/900931/


All Articles