This minor-mode highlights leading spaces with a face and replaces them with a special character so they can easily be counted (this can be disabled).
The whitespace.el package that is built-in to Emacs can be used to accomplish the same effect, but for all spaces, including non-leading spaces between words. This minor-mode only highlights leading spaces that are part of the indentation.
The face to highlight leading spaces with can be customised by changing the
highlight-leading-spaces
face. The character to replace leading spaces
with can be customised by changing highlight-leading-spaces-char
. If you
do not wish to them to be replaced with a special character, set it to a
space.
This minor-mode is quite efficient because it doesn't use overlays but text properties for the leading spaces. Furthermore, the highlights are correctly and efficiently kept up-to-date by plugging in to font-lock, not by adding various hooks.
Install the
highlight-leading-spaces
package.Use the
highlight-leading-spaces-mode
hook to enable this minor-mode:(add-hook 'prog-mode-hook 'highlight-leading-spaces-mode)
Users of use-package can add the following lines to their config:
(use-package highlight-leading-spaces
:ensure t
:defer t
:init (add-hook 'prog-mode-hook 'highlight-leading-spaces-mode))
Download this package and add the following lines to your config.
(add-to-list 'load-path "/path/to/highlight-leading-spaces")
(require 'highlight-leading-spaces)
(add-hook 'prog-mode-hook 'highlight-leading-spaces-mode)
Distributed under the GNU General Public License.