This page is about making particular whitespace characters stand out better.
GnuEmacs 24 has internal variable
‘nobreak-char-display’ (turned on by default), which highlights hard space and hard hyphen characters. But the face is hardwired, and you cannot highlight only one of these chars.
GNU Emacs 22 or later has library
whitespace.el, which lets you highlight whitespace in several ways. See WhiteSpace.
GNU Emacs 21 or later provides option
‘show-trailing-whitespace’ to highlight trailing whitespace in face
‘trailing-whitespace’. For CPerl, you can also specify the face to use. The default face is
‘underline’. You can use face
‘default’ for invisible whitespace:
(setq cperl-invalid-face 'default)
Library highlight-chars.el lets you easily highlight any sets of characters that you choose, including whitespace characters. There are commands and functions to use on hooks.
You can highlight whitespace and other easily confused characters: spaces, tabs, hard spaces, and hard hyphens, as well as trailing whitespace.
For example, command
‘hc-toggle-highlight-tabs’ turns on/off highlighting of tab chars. Or you can turn on tab highlighting by default by adding function
‘font-lock-mode-hook’ in your init file:
(add-hook 'font-lock-mode-hook 'hc-highlight-tabs)
You can turn on/off the highlighting provided by library
Unlike what is offered by libraries such as
whitespace.el, with library
highlight-chars.el you are not limited to whitespace highlighting. You can highlight any set of characters. You can define the set using any number of entries of any of these kinds:
You can use any faces to do this.
In addition, you can exclude any set of characters from this highlighting.
You can thus, for example, highlight all characters in character set
‘greek-iso8859-7’ except `
GREEK SMALL LETTER LAMBDA’. Or all characters in class
[:space:] (whitespace) except
‘tab’. Or all Unicode characters in the range
?\u21ff (mathematical arrows) except
?\u21bb (curved arrows). You get the idea.
BlankMode saves and restores the font-lock state when it is turned on and off. So, if BlankMode is turned on and font-lock is off, BlankMode also turns on the font-lock to highlight blanks, but font-lock is turned off when BlankMode is turned off. So turn on font-lock before BlankMode, if you want font-lock to stay on after BlankMode is turned off.
visws.el - Simple and very easy to use. Shows you tabs, spaces and newlines:
Library redspace.el detects and highlights trailing whitespace.
EightyColumnRule provides highlighting of trailing spaces, TABs, and lines past column 80.
ShowWhitespaceMode shows whitespace in either of two ways:
This code uses font-lock to highlight TABs with face
‘emacs-lisp-mode’ and in
‘text-mode’. You can add an add-hook statement for every other mode you want this for. Put the following in your init file:
(defface extra-whitespace-face '((t (:background "pale green"))) "Used for tabs and such.")
(defvar my-extra-keywords '(("\t" . 'extra-whitespace-face)))
(add-hook 'emacs-lisp-mode-hook (lambda () (font-lock-add-keywords nil my-extra-keywords)))
(add-hook 'text-mode-hook (lambda () (font-lock-add-keywords nil my-extra-keywords)))
To show tabs in the same color as trailing whitespace:
;; Draw tabs with the same color as trailing whitespace (add-hook 'font-lock-mode-hook (lambda () (font-lock-add-keywords nil '(("\t" 0 'trailing-whitespace prepend)))))
To make TAB display as
^I, you can do this:
(standard-display-ascii ?\t "^I")
‘x-stretch-cursor’ to non-
‘nil’ to make the cursor as wide as the character it is over.
If you want to change spaces into TABs or the other way around, use
‘M-x tabify’ or
‘M-x untabify’. See also NoTabs.