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
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

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