(Almost) always highlight non-default indentation

The purpose of this is to highlight indentation characters that betray
your indent-tabs-mode setting. i.e. If you're using tab indentation,
highlight space indentation. If you're using spaces, highlight tab
characters.
This commit is contained in:
Henrik Lissner 2019-02-17 22:12:52 -05:00
parent 3dcd253f71
commit e0519098d9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -459,19 +459,23 @@ instead). Meant for `kill-buffer-query-functions'."
(not (eq (current-buffer) (doom-fallback-buffer))))
(defun doom|highlight-non-default-indentation ()
"Highlight whitespace that doesn't match your `indent-tabs-mode' setting."
"Highlight whitespace that doesn't match your `indent-tabs-mode' setting.
e.g. If you indent with spaces by default, tabs will be highlighted. If you
indent with tabs, spaces at BOL are highlighted.
Does nothing if `whitespace-mode' is already active or the current major mode is
derived from `special-mode'."
(unless (or (bound-and-true-p global-whitespace-mode)
(bound-and-true-p whitespace-mode)
(eq indent-tabs-mode (default-value 'indent-tabs-mode))
(eq major-mode 'fundamental-mode)
(derived-mode-p 'special-mode))
(require 'whitespace)
(set (make-local-variable 'whitespace-style)
(if (or (bound-and-true-p whitespace-mode)
(bound-and-true-p whitespace-newline-mode))
(cl-union (if indent-tabs-mode '(spaces space-mark) '(tabs tab-mark))
(if (bound-and-true-p whitespace-newline-mode)
(cl-union (if indent-tabs-mode '(indentation) '(tabs tab-mark))
whitespace-style)
`(face ,@(if indent-tabs-mode '(spaces space-mark) '(tabs tab-mark))
`(face ,@(if indent-tabs-mode '(indentation) '(tabs tab-mark))
trailing-lines tail)))
(whitespace-mode +1)))