Refactor doom-highlight-non-default-indentation-h

And revise its docstring.
This commit is contained in:
Henrik Lissner
2020-08-02 22:48:46 -04:00
parent 1406a45750
commit e2855db2a6

View File

@ -133,8 +133,9 @@ An omitted font size means to inherit `doom-font''s size.")
(defun doom-highlight-non-default-indentation-h ()
"Highlight whitespace at odds with `indent-tabs-mode'.
That is, highlight tabs if the usual indentation is with spaces, and highlight
spaces at the beginnings of lines if the usual indentation is with tabs.
That is, highlight tabs if `indent-tabs-mode' is `nil', and highlight spaces at
the beginnings of lines if `indent-tabs-mode' is `t'. The purpose is to make
incorrect indentation in the current buffer obvious to you.
Does nothing if `whitespace-mode' or `global-whitespace-mode' is already active
or if the current buffer is read-only or not file-visiting."
@ -143,11 +144,12 @@ or if the current buffer is read-only or not file-visiting."
(null buffer-file-name))
(require 'whitespace)
(set (make-local-variable 'whitespace-style)
(let ((style (if indent-tabs-mode '(indentation) '(tabs tab-mark))))
(if whitespace-mode
(cl-union style whitespace-active-style)
style)))
(cl-pushnew 'face whitespace-style)
(cl-union (if indent-tabs-mode
'(indentation)
'(tabs tab-mark))
(when whitespace-mode
(remq 'face whitespace-active-style))))
(cl-pushnew 'face whitespace-style) ; must be first
(whitespace-mode +1)))