I've been banging my head with this for some time; I'm sorry if the question is idiotic or trivial.
I'd quite like to, in every buffer, show certain whitespace characters in a dimmed face. If I manually execute the following block of elisp, and then manually turn (off and) on whitespace-mode, it works as expected:
(setq
global-whitespace-mode t
whitespace-style '(face tabs tab-mark spaces space-mark trailing lines-tail newline newline-mark)
whitespace-display-mappings '(
(space-mark ?\ [?\u00B7] [?.])
(space-mark ?\xA0 [?\u00A4] [?_])
(newline-mark ?\n [?卢 ?\n])
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])))
However, having the following chunk of code in config.el does not work:
(use-package! whitespace
:config
(setq
global-whitespace-mode t
whitespace-style '(face tabs tab-mark spaces space-mark trailing lines-tail newline newline-mark)
whitespace-display-mappings '(
(space-mark ?\ [?\u00B7] [?.])
(space-mark ?\xA0 [?\u00A4] [?_])
(newline-mark ?\n [?卢 ?\n])
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t]))))
Specifically, the following occurs.
global-whitespace-mode is set to t and whitespace-style is set to (face tabs tab-mark spaces space-mark trailing lines-tail newline newline-mark), as expected, but whitespace-mode is set to nil.config.el, whitespace-style is then set to (face tabs tab-mark) and whitespace-mode is set to t.I have no real idea about what's going on. Any help or advice would be really appreciated.
(setq global-whitespace-mode t)
To enable any mode, major or minor, local or global, you must call its function, not set its variable. The latter does nothing but inform Emacs that the mode is enabled, without actually activating it.
(global-whitespace-mode +1) will do it.
If I then open up config.el, whitespace-style is then set to (face tabs tab-mark) and whitespace-mode is set to t.
By default, if you haven't activated whitespace-mode yourself, Doom uses it to highlight incorrect indentation in your buffers and activates it for you.
Hope that helps!
This works wonderfully. Thanks!
How would someone best go about learning exactly how Emacs and elisp work, do you think? I always feel as though I'm moving things around in a blind hope; I've little real understanding.
I think setting up your own handling of whitespace-style should be added to FAQ.
It took me quite a while to realise that I had to call (global-whitespace-mode t)
My use case is that I occasionally want to run (whitespace-cleanup) to remove trailing whitespace.
I can make a pull request for the documentation change, if that is desired.
Most helpful comment
To enable any mode, major or minor, local or global, you must call its function, not set its variable. The latter does nothing but inform Emacs that the mode is enabled, without actually activating it.
(global-whitespace-mode +1)will do it.By default, if you haven't activated whitespace-mode yourself, Doom uses it to highlight incorrect indentation in your buffers and activates it for you.
Hope that helps!