Subject: 24.2; makefile-mode whitespace-cleanup

From: Arthur Azevedo de Amorim <[email-masked]>
Date: Thu, 18 Oct 2012 11:37:35 -0400

Hello,

I found a subtle bug while editing Makefiles using whitespace-cleanup
in my after-save-hook. I'm using emacs-24.2.

Suppose that I have the following in .emacs:

(setq-default indent-tabs-mode nil)
(add-hook 'after-save-hook 'whitespace-cleanup)

I open up emacs, visit a text file, and then save it.
whitespace-cleanup gets triggered. After that, I visit a Makefile.
Now, if I save the file, whitespace-cleanup converts tabs to 8 spaces.
Conversely, if I open first the Makefile, and then any other file,
whitespace-cleanup will convert 8 spaces in the text file to tabs.

I think I know where the problem is. whitespace.el has the following line

(defvar whitespace-indent-tabs-mode indent-tabs-mode)

When whitespace-cleanup is called for the first time on the text file,
the value of indent-tabs-mode is nil, because that is the default
value and text mode doesn't override it. When the Makefile is visited,
whitespace-indent-tabs-mode has already been defined, and so will
still be nil.

A way to fix the problem (I think) would be to remove
whitespace-indent-tabs-mode and simply use indent-tabs-mode instead.

I believe that functionality related to other buffer-local variables
would suffer from the same problem. For instance, the line below
defines whitespace-tab-width similarly.

-- 
Arthur Azevedo de Amorim