When I open the Linux Kernel code, my default indentation conflicts with the desired formatting of the Kernel. I use Emacs Prelude, so I added the settings from this link to my c-mode-common-hook
. I constrain the indentation only to the Kernel code base by checking the path of the opened file, as they did on the link.
However, one problem remained. Since the Kernel codebase uses tabs and my global whitespace-style
is set to '(face tabs empty trailing lines-tail)
, a bunch of whitespaces in the Kernel code are highlighted. How can I disable tab highlighting within my c-mode-common-hook
?
Note that I still want to keep highlighting in other buffers that are not the part of the Kernel codebase.
Update: It looks like setting buffer-local variable does not solve the problem. If I do:
(setq-local whitespace-style (remq 'tabs whitespace-style)
in c-mode-common-hook
, it does correctly set the buffer-local variable. I can check it by doing M-: whitespace-style
in a Kernel code buffer (it shows the new value I set). However, the buffer still highlights the tabs. It is only when I do M-x whitespace-mode
once to disable it, and once more to enable it again that the highlight actually disappears. Unluckily, if I add two (whitespace-mode)
in c-mode-common-hook
after setting the buffer-local variable, it does not have the same effect as when I call it with M-x
once the buffer is fully initialized.
whitespace-style
is a global variable, which I determined by evaluating(require 'whitespace)
and thenC-h v
(akaM-x describe-variable
), enter the variable name, and reading the*Help*
buffer. Some popular libraries take a global variable and make it a buffer-local variable and then set the value for that particular buffer. This can be accomplished by ensuring the target buffer has focus and calling(make-local-variable 'whitespace-style)
and then (while the target buffer has focus) call(setq whitespace-style ...)
and the value set will be buffer-local. – lawlist Dec 7 '19 at 8:23(whitespace-mode)
is equivalent to(whitespace-mode 1)
. i.e. it doesn't toggle, it just enables. This goes for minor modes in general. You could try(whitespace-mode -1) (whitespace-mode 1)
, but it will be better to set the desired style before calling it in the first place. Depending on the final approach this might entail adding a(require 'whitespace)
as well, to ensurewhitespace-style
exists. – phils Dec 7 '19 at 21:42