I have the following in my .emacs file:
(defun c++-mode-untabify ()
(save-excursion
(goto-char (point-min))
(while (re-search-forward \"[ \\t]+
The documentation in my Emacs says that make-local-hook is now obsolete as of 21.1, since add-hook now takes an optional argument for making a hook buffer-local. So you could try:
(add-hook 'c++-mode-hook
'(lambda ()
(add-hook 'write-contents-hooks 'c++-mode-untabify nil t)))
Another option is to have the c++-mode-untabify function check the current mode. I'd probably just write that as something like:
(defun c++-mode-untabify ()
(if (string= (substring mode-name 0 3) "C++")
(save-excursion
(delete-trailing-whitespace)
(untabify (point-min) (point-max)))))