Doom-emacs: How do I... use whitespace-mode with doom-emacs?

Created on 5 Mar 2020  路  3Comments  路  Source: hlissner/doom-emacs

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.

  1. If I launch a new Emacs session, a blank buffer in Fundamental mode is created. In this, 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.
  2. If I then open up 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.

question

Most helpful comment

(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!

All 3 comments

(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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AloisJanicek picture AloisJanicek  路  3Comments

luisenrike picture luisenrike  路  3Comments

governorgoat picture governorgoat  路  3Comments

waymondo picture waymondo  路  3Comments

askurihin picture askurihin  路  3Comments