Enabling whitespace mode on emacs

1.1k Views Asked by At

I'm trying to enable whitespace mode but it doesn't seem to be working for me.

I've added the whitespace.el file to my .emacs.d/ directory. I added the following lines to me .emacs file:

(add-hook 'before-save-hook 'whitespace-cleanup)
(add-hook 'before-save-hook (lambda() (delete-trailing-whitespace)))

(require 'whitespace)

I did the following in the whitespace.el file:

M-x byte-compile-file <path to whitespace.el>

I tried executing the following command from any random text in emacs (e.g.: test.c):

M-x whitespace-toggle-options RET

But I just get a message saying [No match]

What am I missing?

Also, will I have to type in a command to enable the whitespace-mode every time I use emacs?

1

There are 1 best solutions below

0
On BEST ANSWER

whitespace.el has been included in Emacs for quite a while. Unless you have a very old version, you shouldn't need to manually put it anywhere, or do anything particularly special to use it.

whitespace-toggle-options probably isn't the function you want to use. Instead, try whitespace-mode:

Toggle whitespace visualization (Whitespace mode). With a prefix argument ARG, enable Whitespace mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil.

If you want to enable it by default, add

(global-whitespace-mode)

to your init file.