ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

18.12 Useless Whitespace

It is easy to leave unnecessary spaces at the end of a line, or empty lines at the end of a file, without realizing it. In most cases, this trailing whitespace has no effect, but there are special circumstances where it matters, and it can be a nuisance.

You can make trailing whitespace at the end of a line visible by setting the buffer-local variable show-trailing-whitespace to t. Then Emacs displays trailing whitespace, using the face trailing-whitespace.

This feature does not apply when point is at the end of the line containing the whitespace. Strictly speaking, that is “trailing whitespace” nonetheless, but displaying it specially in that case looks ugly while you are typing in new text. In this special case, the location of point is enough to show you that the spaces are present.

To delete all trailing whitespace within the buffer's accessible portion (see Narrowing), type M-x delete-trailing-whitespace <RET>. This command does not remove newline characters.

Emacs can indicate unused lines at the end of the window with a small image in the left fringe (see Fringes). The image appears for window lines that do not correspond to any buffer text. Blank lines at the end of the buffer then stand out because they do not have this image in the fringe.

To enable this feature, set the buffer-local variable indicate-empty-lines to a non-nil value. You can enable or disable this feature for all new buffers by setting the default value of this variable, ⁖ (setq-default indicate-empty-lines t);. (This feature currently doesn't work on text-only terminals.)

blog comments powered by Disqus